Skip to content

Instantly share code, notes, and snippets.

@ConnorNelson
Created March 16, 2018 05:43
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 ConnorNelson/07229c0a55aaf05571c26c854c300e33 to your computer and use it in GitHub Desktop.
Save ConnorNelson/07229c0a55aaf05571c26c854c300e33 to your computer and use it in GitHub Desktop.
iCTF 2018 - Hack The Planet
#!/usr/bin/env python2
# This code was written 10 hours before the competition, yikes
# Any bugs are your problem
import socks # pip install PySocks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 4444)
socket.socket = socks.socksocket
from pwn import * # pip install pwntools
from swpag_client import Team # pip install swpag_client
import time
team = Team(None, "YOUR_SWPAG_TEAM_FLAG_TOKEN_HERE")
def team_ip(team_host):
# 172.31.129.1 (team1) ... 172.31.129.254 (team254) ... 172.31.130.1 (team255) ...
team_number = int(team_host[4:])
minor = ((team_number - 1) % 254) + 1
major = (team_number / 255) + 129
return '172.31.{major}.{minor}'.format(major=major, minor=minor)
services = team.get_service_list()
service_flag_ids = dict()
while True:
for service in services:
print("Going to attack", service['service_name'])
if service['service_name'] not in service_flag_ids:
service_flag_ids[service['service_name']] = set()
targets = team.get_targets(service['service_id'])
for target in targets['targets']:
flag_id = target['flag_id']
ip = team_ip(target['hostname'])
port = target['port']
if flag_id not in service_flag_ids[service['service_name']]:
try:
conn = remote(ip, port, timeout=3)
# insert pwnage here
conn.close()
flag = "GET_THE_FLAG"
# result = team.submit_flag(flag)
# print(result)
print("HACKED")
except Exception as e:
print("Error connecting to", target['team_name'], target['hostname'], ip, port)
print(e)
service_flag_ids[service['service_name']].add(flag_id)
time.sleep(10) # DOS is against the rules
@ConnorNelson
Copy link
Author

ssh -D 4444 -q -C -N -f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment