Skip to content

Commit d224eef

Browse files
authored
Add files via upload
1 parent e483bae commit d224eef

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
title: "OverTheWire Bandit: Level 20 to Level 21"
3+
date: 2026-07-01 01:05:00 +0500
4+
categories: [CTF, Bandit]
5+
tags: [linux, netcat, job-control, setuid, networking, tmux, screen, overthewire, beginner]
6+
---
7+
8+
## The Goal
9+
10+
A setuid binary called `suconnect` connects to a port on localhost. If it receives the correct password for bandit20, it sends back bandit21's password. The challenge: you need a listener running and ready before `suconnect` connects to it — both things have to happen at the same time in one terminal.
11+
12+
## What I Did
13+
14+
Listed the home directory and ran the binary without arguments:
15+
16+
```bash
17+
bandit20@bandit:~$ ./suconnect
18+
Usage: ./suconnect <portnumber>
19+
This program will connect to the given port on localhost using TCP.
20+
If it receives the correct password from the other side, the next password is transmitted back.
21+
```
22+
23+
Confirmed it was setuid:
24+
25+
```bash
26+
bandit20@bandit:~$ ls -l suconnect
27+
-rwsr-x--- 1 bandit21 bandit20 15604 Jun 24 14:59 suconnect
28+
```
29+
30+
Owned by bandit21 with the setuid bit set — it runs as bandit21, which means it can read `/etc/bandit_pass/bandit21`.
31+
32+
### Setting Up the Listener with Job Control
33+
34+
Started netcat as a listener in the background using `&`:
35+
36+
```bash
37+
nc -l -p 1234 &
38+
[1] 538
39+
```
40+
41+
This put nc in the background. The `[1]` is the job number. The terminal returned immediately, ready for the next command.
42+
43+
Ran suconnect also in the background:
44+
45+
```bash
46+
./suconnect 1234 &
47+
[2] 548
48+
```
49+
50+
Brought the nc listener to the foreground so I could type into it:
51+
52+
```bash
53+
fg %1
54+
nc -l -p 1234
55+
```
56+
57+
Typed the bandit20 password:
58+
59+
```
60+
4pIjcunZ0fK2vmp3IwfG8Vf7VhxD6pOA
61+
Read: 4pIjcunZ0fK2vmp3IwfG8Vf7VhxD6pOA
62+
Password matches, sending next password
63+
bW9kBv5WC3P4yoDyf12LSdGuNz5ka6hY
64+
[2] Done ./suconnect 1234
65+
```
66+
67+
## How Job Control Works
68+
69+
Linux job control lets you manage multiple processes within a single terminal session:
70+
71+
| Command | What it does |
72+
|---|---|
73+
| `command &` | Starts a command in the background immediately |
74+
| `Ctrl+Z` | Suspends (pauses) the current foreground process |
75+
| `bg` | Resumes a suspended process in the background |
76+
| `fg` | Brings a background or suspended process to the foreground |
77+
| `jobs` | Lists all background and suspended jobs |
78+
| `fg %1` | Brings job number 1 specifically to the foreground |
79+
80+
The flow in this level:
81+
1. Start nc listener in background with `&`
82+
2. Start suconnect in background with `&`
83+
3. Bring nc to the foreground with `fg %1`
84+
4. Type the password — nc sends it to suconnect
85+
5. suconnect validates it and sends back the next password
86+
87+
## Alternative Methods
88+
89+
**Piping the password directly into nc:**
90+
```bash
91+
echo "4pIjcunZ0fK2vmp3IwfG8Vf7VhxD6pOA" | nc -l -p 1234 &
92+
./suconnect 1234
93+
```
94+
This pipes the password into nc before it starts listening, so when suconnect connects, nc automatically sends the password without needing interactive input.
95+
96+
**Using tmux:**
97+
```bash
98+
tmux
99+
```
100+
Split the terminal into two panes with `Ctrl+B` then `%`. Run the listener in one pane and suconnect in the other. No job control needed — each pane is an independent shell.
101+
102+
**Using screen:**
103+
```bash
104+
screen
105+
```
106+
Create two windows with `Ctrl+A` then `c`. Switch between them with `Ctrl+A` then `n`. Same idea as tmux but older interface.
107+
108+
## What I Learned
109+
110+
**Job control is essential for running multiple things in one terminal.** The `&` operator is the most commonly used — it lets you start a background process and immediately get your prompt back.
111+
112+
**`fg %n` specifies which job to bring forward.** Without the number, `fg` brings the most recent job. With `%1` you control exactly which one.
113+
114+
**Netcat in listener mode waits for a connection.** `nc -l -p PORT` sits waiting until something connects. Once a connection arrives and the session ends, it exits. Use `-k` to keep listening for multiple connections.
115+
116+
**tmux and screen solve the same problem differently.** Job control uses one shell and switches between processes. tmux and screen give you genuinely separate shells running simultaneously — more flexible, especially over SSH where you might lose connection and want sessions to survive.
117+
118+
## Commands Used
119+
120+
| Command | What it did |
121+
|---|---|
122+
| `nc -l -p 1234 &` | Started netcat listener on port 1234 in background |
123+
| `./suconnect 1234 &` | Started suconnect in background |
124+
| `fg %1` | Brought nc to foreground to type the password |
125+
| `jobs` | Checked what was running in background |

0 commit comments

Comments
 (0)