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
| r2 -A -q -c "pdf @ sym.main" /challenge/byte-budget
; ICOD XREF from entry0 @ 0x1241(r) ┌ 727: int main (int argc, char **argv, char **envp); │ `- args(rdi, rsi, rdx) vars(6:sp[0x10..0x40]) │ 0x00001567 f30f1efa endbr64 │ 0x0000156b 55 push rbp │ 0x0000156c 4889e5 mov rbp, rsp │ 0x0000156f 4883ec40 sub rsp, 0x40 │ 0x00001573 897ddc mov dword [var_24h], edi ; argc │ 0x00001576 488975d0 mov qword [var_30h], rsi ; argv │ 0x0000157a 488955c8 mov qword [var_38h], rdx ; envp │ 0x0000157e 488b059b2a.. mov rax, qword [obj.stdin] ; obj.stdin__GLIBC_2.2.5 │ ; [0x4020:8]=0 │ 0x00001585 b900000000 mov ecx, 0 ; size_t size │ 0x0000158a ba02000000 mov edx, 2 ; int mode │ 0x0000158f be00000000 mov esi, 0 ; char *buf │ 0x00001594 4889c7 mov rdi, rax ; FILE*stream │ 0x00001597 e844fcffff call sym.imp.setvbuf ; int setvbuf(FILE*stream, char *buf, int mode, size_t size) │ 0x0000159c 488b056d2a.. mov rax, qword [obj.stdout] ; obj.__TMC_END__ │ ; [0x4010:8]=0 │ 0x000015a3 b900000000 mov ecx, 0 ; size_t size │ 0x000015a8 ba02000000 mov edx, 2 ; int mode │ 0x000015ad be00000000 mov esi, 0 ; char *buf │ 0x000015b2 4889c7 mov rdi, rax ; FILE*stream │ 0x000015b5 e826fcffff call sym.imp.setvbuf ; int setvbuf(FILE*stream, char *buf, int mode, size_t size) │ 0x000015ba 488d3d040c.. lea rdi, [0x000021c5] ; "###" ; const char *s │ 0x000015c1 e87afbffff call sym.imp.puts ; int puts(const char *s) │ 0x000015c6 488b45d0 mov rax, qword [var_30h] │ 0x000015ca 488b00 mov rax, qword [rax] │ 0x000015cd 4889c6 mov rsi, rax │ 0x000015d0 488d3df20b.. lea rdi, str._Welcome_to__s__n ; 0x21c9 ; "### Welcome to %s!\n" ; const char *format │ 0x000015d7 b800000000 mov eax, 0 │ 0x000015dc e89ffbffff call sym.imp.printf ; int printf(const char *format) │ 0x000015e1 488d3ddd0b.. lea rdi, [0x000021c5] ; "###" ; const char *s │ 0x000015e8 e853fbffff call sym.imp.puts ; int puts(const char *s) │ 0x000015ed bf0a000000 mov edi, 0xa ; int c │ 0x000015f2 e839fbffff call sym.imp.putchar ; int putchar(int c) │ 0x000015f7 488d3de20b.. lea rdi, str.This_challenge_reads_in_some_bytes__modifies_them__depending_on_the_specific_challenge_configuration___and_executes_them ; 0x21e0 ; "This challenge reads in some bytes, modifies them (depending on the specific challenge configuration), and executes them" ; const char *s │ 0x000015fe e83dfbffff call sym.imp.puts ; int puts(const char *s) │ 0x00001603 488d3d560c.. lea rdi, str.as_code__This_is_a_common_exploitation_scenario__called__code_injection_._Through_this_series_of_challenges__you_will ; 0x2260 ; "as code! This is a common exploitation scenario, called `code injection`. Through this series of challenges, you will" ; const char *s │ 0x0000160a e831fbffff call sym.imp.puts ; int puts(const char *s) │ 0x0000160f 488d3dc20c.. lea rdi, str.practice_your_shellcode_writing_skills_under_various_constraints__To_ensure_that_you_are_shellcoding__rather_than_doing ; 0x22d8 ; "practice your shellcode writing skills under various constraints! To ensure that you are shellcoding, rather than doing" ; const char *s │ 0x00001616 e825fbffff call sym.imp.puts ; int puts(const char *s) │ 0x0000161b 488d3d2e0d.. lea rdi, str.other_tricks__this_will_sanitize_all_environment_variables_and_arguments_and_close_all_file_descriptors___2._n ; 0x2350 ; "other tricks, this will sanitize all environment variables and arguments and close all file descriptors > 2.\n" ; const char *s │ 0x00001622 e819fbffff call sym.imp.puts ; int puts(const char *s) │ 0x00001627 c745ec0300.. mov dword [fildes], 3 │ ┌─< 0x0000162e eb0e jmp 0x163e │ │ ; CODE XREF from main @ 0x1645(x) │ ┌──> 0x00001630 8b45ec mov eax, dword [fildes] │ ╎│ 0x00001633 89c7 mov edi, eax ; int fildes │ ╎│ 0x00001635 e876fbffff call sym.imp.close ; int close(int fildes) │ ╎│ 0x0000163a 8345ec01 add dword [fildes], 1 │ ╎│ ; CODE XREF from main @ 0x162e(x) │ ╎└─> 0x0000163e 817dec0f27.. cmp dword [fildes], 0x270f ; '\x0f\'' │ └──< 0x00001645 7ee9 jle 0x1630 │ 0x00001647 488b45d0 mov rax, qword [var_30h] │ 0x0000164b 488945f0 mov qword [s], rax │ ┌─< 0x0000164f eb2b jmp 0x167c │ │ ; CODE XREF from main @ 0x1686(x) │ ┌──> 0x00001651 488b45f0 mov rax, qword [s] │ ╎│ 0x00001655 488b00 mov rax, qword [rax] │ ╎│ 0x00001658 4889c7 mov rdi, rax ; const char *s │ ╎│ 0x0000165b e800fbffff call sym.imp.strlen ; size_t strlen(const char *s) │ ╎│ 0x00001660 4889c2 mov rdx, rax ; size_t n │ ╎│ 0x00001663 488b45f0 mov rax, qword [s] │ ╎│ 0x00001667 488b00 mov rax, qword [rax] │ ╎│ 0x0000166a be00000000 mov esi, 0 ; int c │ ╎│ 0x0000166f 4889c7 mov rdi, rax ; void *s │ ╎│ 0x00001672 e829fbffff call sym.imp.memset ; void *memset(void *s, int c, size_t n) │ ╎│ 0x00001677 488345f008 add qword [s], 8 │ ╎│ ; CODE XREF from main @ 0x164f(x) │ ╎└─> 0x0000167c 488b45f0 mov rax, qword [s] │ ╎ 0x00001680 488b00 mov rax, qword [rax] │ ╎ 0x00001683 4885c0 test rax, rax │ └──< 0x00001686 75c9 jne 0x1651 │ 0x00001688 488b45c8 mov rax, qword [var_38h] │ 0x0000168c 488945f8 mov qword [var_8h], rax │ ┌─< 0x00001690 eb2b jmp 0x16bd │ │ ; CODE XREF from main @ 0x16c7(x) │ ┌──> 0x00001692 488b45f8 mov rax, qword [var_8h] │ ╎│ 0x00001696 488b00 mov rax, qword [rax] │ ╎│ 0x00001699 4889c7 mov rdi, rax ; const char *s │ ╎│ 0x0000169c e8bffaffff call sym.imp.strlen ; size_t strlen(const char *s) │ ╎│ 0x000016a1 4889c2 mov rdx, rax ; size_t n │ ╎│ 0x000016a4 488b45f8 mov rax, qword [var_8h] │ ╎│ 0x000016a8 488b00 mov rax, qword [rax] │ ╎│ 0x000016ab be00000000 mov esi, 0 ; int c │ ╎│ 0x000016b0 4889c7 mov rdi, rax ; void *s │ ╎│ 0x000016b3 e8e8faffff call sym.imp.memset ; void *memset(void *s, int c, size_t n) │ ╎│ 0x000016b8 488345f808 add qword [var_8h], 8 │ ╎│ ; CODE XREF from main @ 0x1690(x) │ ╎└─> 0x000016bd 488b45f8 mov rax, qword [var_8h] │ ╎ 0x000016c1 488b00 mov rax, qword [rax] │ ╎ 0x000016c4 4885c0 test rax, rax │ └──< 0x000016c7 75c9 jne 0x1692 │ 0x000016c9 41b900000000 mov r9d, 0 ; size_t offset │ 0x000016cf 41b800000000 mov r8d, 0 ; int fd │ 0x000016d5 b922000000 mov ecx, 0x22 ; '\"' ; int flags │ 0x000016da ba07000000 mov edx, 7 ; int prot │ 0x000016df be00100000 mov esi, sym._init ; 0x1000 ; size_t length │ 0x000016e4 bf00f0f514 mov edi, 0x14f5f000 ; void*addr │ 0x000016e9 e882faffff call sym.imp.mmap ; void*mmap(void*addr, size_t length, int prot, int flags, int fd, size_t offset) │ 0x000016ee 4889054329.. mov qword [obj.shellcode], rax ; [0x4038:8]=0 │ 0x000016f5 488b053c29.. mov rax, qword [obj.shellcode] ; [0x4038:8]=0 │ 0x000016fc 483d00f0f514 cmp rax, 0x14f5f000 │ ┌─< 0x00001702 741f je 0x1723 │ │ 0x00001704 488d0d360e.. lea rcx, obj.__PRETTY_FUNCTION__.25265 ; 0x2541 ; "main" ; const char *function │ │ 0x0000170b ba62000000 mov edx, 0x62 ; 'b' ; unsigned int line │ │ 0x00001710 488d35a90c.. lea rsi, str._challenge_babyshell_level_8.c ; 0x23c0 ; "/challenge/babyshell-level-8.c" ; const char *file │ │ 0x00001717 488d3dc20c.. lea rdi, str.shellcode___void__0x14f5f000 ; str.shellcode___void__0x14f5f000 │ │ ; 0x23e0 ; "shellcode == (void *)0x14f5f000" ; const char *assertion │ │ 0x0000171e e86dfaffff call sym.imp.__assert_fail ; void __assert_fail(const char *assertion, const char *file, unsigned int line, const char *function) │ │ ; CODE XREF from main @ 0x1702(x) │ └─> 0x00001723 488b050e29.. mov rax, qword [obj.shellcode] ; [0x4038:8]=0 │ 0x0000172a 4889c6 mov rsi, rax │ 0x0000172d 488d3dcc0c.. lea rdi, str.Mapped_0x1000_bytes_for_shellcode_at__p__n ; str.Mapped_0x1000_bytes_for_shellcode_at__p__n │ ; 0x2400 ; "Mapped 0x1000 bytes for shellcode at %p!\n" ; const char *format │ 0x00001734 b800000000 mov eax, 0 │ 0x00001739 e842faffff call sym.imp.printf ; int printf(const char *format) │ 0x0000173e 488d3deb0c.. lea rdi, str.Reading_0x12_bytes_from_stdin._n ; str.Reading_0x12_bytes_from_stdin._n │ ; 0x2430 ; "Reading 0x12 bytes from stdin.\n" ; const char *s │ 0x00001745 e8f6f9ffff call sym.imp.puts ; int puts(const char *s) │ 0x0000174a 488b05e728.. mov rax, qword [obj.shellcode] ; [0x4038:8]=0 │ 0x00001751 ba12000000 mov edx, 0x12 ; size_t nbyte │ 0x00001756 4889c6 mov rsi, rax ; void *buf │ 0x00001759 bf00000000 mov edi, 0 ; int fildes │ 0x0000175e e85dfaffff call sym.imp.read ; ssize_t read(int fildes, void *buf, size_t nbyte) │ 0x00001763 488905c628.. mov qword [obj.shellcode_size], rax ; [0x4030:8]=0 │ 0x0000176a 488b05bf28.. mov rax, qword [obj.shellcode_size] ; [0x4030:8]=0 │ 0x00001771 4885c0 test rax, rax │ ┌─< 0x00001774 751f jne 0x1795 │ │ 0x00001776 488d0dc40d.. lea rcx, obj.__PRETTY_FUNCTION__.25265 ; 0x2541 ; "main" ; const char *function │ │ 0x0000177d ba67000000 mov edx, 0x67 ; 'g' ; unsigned int line │ │ 0x00001782 488d35370c.. lea rsi, str._challenge_babyshell_level_8.c ; 0x23c0 ; "/challenge/babyshell-level-8.c" ; const char *file │ │ 0x00001789 488d3dc00c.. lea rdi, str.shellcode_size___0 ; 0x2450 ; "shellcode_size > 0" ; const char *assertion │ │ 0x00001790 e8fbf9ffff call sym.imp.__assert_fail ; void __assert_fail(const char *assertion, const char *file, unsigned int line, const char *function) │ │ ; CODE XREF from main @ 0x1774(x) │ └─> 0x00001795 488d3dcc0c.. lea rdi, str.Removing_write_permissions_from_first_4096_bytes_of_shellcode._n ; 0x2468 ; "Removing write permissions from first 4096 bytes of shellcode.\n" ; const char *s │ 0x0000179c e89ff9ffff call sym.imp.puts ; int puts(const char *s) │ 0x000017a1 488b059028.. mov rax, qword [obj.shellcode] ; [0x4038:8]=0 │ 0x000017a8 ba05000000 mov edx, 5 │ 0x000017ad be00100000 mov esi, sym._init ; 0x1000 │ 0x000017b2 4889c7 mov rdi, rax │ 0x000017b5 e846faffff call sym.imp.mprotect │ 0x000017ba 85c0 test eax, eax │ ┌─< 0x000017bc 741f je 0x17dd │ │ 0x000017be 488d0d7c0d.. lea rcx, obj.__PRETTY_FUNCTION__.25265 ; 0x2541 ; "main" ; const char *function │ │ 0x000017c5 ba6a000000 mov edx, 0x6a ; 'j' ; unsigned int line │ │ 0x000017ca 488d35ef0b.. lea rsi, str._challenge_babyshell_level_8.c ; 0x23c0 ; "/challenge/babyshell-level-8.c" ; const char *file │ │ 0x000017d1 488d3dd00c.. lea rdi, str.mprotect_shellcode__4096__PROT_READPROT_EXEC___0 ; 0x24a8 ; "mprotect(shellcode, 4096, PROT_READ|PROT_EXEC) == 0" ; const char *assertion │ │ 0x000017d8 e8b3f9ffff call sym.imp.__assert_fail ; void __assert_fail(const char *assertion, const char *file, unsigned int line, const char *function) │ │ ; CODE XREF from main @ 0x17bc(x) │ └─> 0x000017dd 488d3dfc0c.. lea rdi, str.This_challenge_is_about_to_execute_the_following_shellcode:_n ; 0x24e0 ; "This challenge is about to execute the following shellcode:\n" ; const char *s │ 0x000017e4 e857f9ffff call sym.imp.puts ; int puts(const char *s) │ 0x000017e9 488b154028.. mov rdx, qword [obj.shellcode_size] ; [0x4030:8]=0 │ 0x000017f0 488b054128.. mov rax, qword [obj.shellcode] ; [0x4038:8]=0 │ 0x000017f7 4889d6 mov rsi, rdx ; int64_t arg2 │ 0x000017fa 4889c7 mov rdi, rax ; int64_t arg1 │ 0x000017fd e807fbffff call sym.print_disassembly │ 0x00001802 488d3d140d.. lea rdi, [0x0000251d] ; const char *s │ 0x00001809 e832f9ffff call sym.imp.puts ; int puts(const char *s) │ 0x0000180e 488d3d090d.. lea rdi, str.Executing_shellcode__n ; 0x251e ; "Executing shellcode!\n" ; const char *s │ 0x00001815 e826f9ffff call sym.imp.puts ; int puts(const char *s) │ 0x0000181a 488b051728.. mov rax, qword [obj.shellcode] ; [0x4038:8]=0 # shellcode in rdx │ 0x00001821 4889c2 mov rdx, rax │ 0x00001824 b800000000 mov eax, 0 │ 0x00001829 ffd2 call rdx │ 0x0000182b 488d3d020d.. lea rdi, str._Goodbye_ ; 0x2534 ; "### Goodbye!" ; const char *s │ 0x00001832 e809f9ffff call sym.imp.puts ; int puts(const char *s) │ 0x00001837 b800000000 mov eax, 0 │ 0x0000183c c9 leave └ 0x0000183d c3 ret
|