-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathpager_payload.sh
More file actions
369 lines (326 loc) · 10.4 KB
/
pager_payload.sh
File metadata and controls
369 lines (326 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#!/bin/sh
# Title: Ragnar
# Description: Autonomous network reconnaissance and security scanning tool for WiFi Pineapple Pager - Network scanning, vulnerability assessment, brute force, and data exfiltration with Viking personality
# Author: PierreGode / Ragnar Project
# Version: 1.2
# Category: Reconnaissance
# Library: libpagerctl.so (pagerctl)
# Payload directory (standard Pager installation path)
PAYLOAD_DIR="/root/payloads/user/reconnaissance/pager_ragnar"
DATA_DIR="$PAYLOAD_DIR/data"
LOG_FILE="$DATA_DIR/payload.log"
# Create data directory early so we can log
mkdir -p "$DATA_DIR" 2>/dev/null
# Internal logging helper - always writes to file, uses DuckyScript LOG when available
_log() {
local color=""
local msg="$*"
if [ $# -ge 2 ]; then
case "$1" in
red|green|yellow|cyan|blue|magenta|purple)
color="$1"
shift
msg="$*"
;;
esac
fi
echo "[$(date '+%H:%M:%S')] $msg" >> "$LOG_FILE" 2>/dev/null
if [ -n "$color" ]; then
LOG "$color" "$msg" 2>/dev/null || true
else
LOG "$msg" 2>/dev/null || true
fi
}
cd "$PAYLOAD_DIR" || {
LOG "red" "ERROR: $PAYLOAD_DIR not found"
exit 1
}
# Truncate log on fresh start
echo "=== Ragnar payload started $(date) ===" > "$LOG_FILE"
#
# Find and setup pagerctl dependencies (libpagerctl.so + pagerctl.py)
# Check bundled locations first, then PAGERCTL utilities dir
#
PAGERCTL_FOUND=false
for dir in "$PAYLOAD_DIR/lib" "$PAYLOAD_DIR" "/root/lib" "/mmc/root/payloads/user/utilities/PAGERCTL"; do
if [ -f "$dir/libpagerctl.so" ]; then
PAGERCTL_DIR="$dir"
PAGERCTL_FOUND=true
_log "Found libpagerctl.so in $dir"
break
fi
done
if [ "$PAGERCTL_FOUND" = false ]; then
LOG ""
LOG "red" "=== MISSING DEPENDENCY ==="
LOG ""
LOG "red" "libpagerctl.so not found!"
LOG ""
LOG "Searched:"
for dir in "$PAYLOAD_DIR/lib" "$PAYLOAD_DIR" "/root/lib" "/mmc/root/payloads/user/utilities/PAGERCTL"; do
LOG " $dir"
done
LOG ""
LOG "Install PAGERCTL payload or copy files to:"
LOG " $PAYLOAD_DIR/lib/"
LOG ""
LOG "Press any button to exit..."
WAIT_FOR_INPUT >/dev/null 2>&1
exit 1
fi
# If pagerctl files aren't in our lib dir, copy them there
if [ "$PAGERCTL_DIR" != "$PAYLOAD_DIR/lib" ]; then
mkdir -p "$PAYLOAD_DIR/lib" 2>/dev/null
cp "$PAGERCTL_DIR/libpagerctl.so" "$PAYLOAD_DIR/lib/" 2>/dev/null
[ -f "$PAGERCTL_DIR/pagerctl.py" ] && cp "$PAGERCTL_DIR/pagerctl.py" "$PAYLOAD_DIR/lib/" 2>/dev/null
LOG "green" "Copied pagerctl from $PAGERCTL_DIR"
fi
#
# Setup local paths for bundled binaries and libraries
# Uses libpagerctl.so for display/input handling
# MMC paths needed when python3 installed with opkg -d mmc
#
export PATH="/mmc/usr/bin:$PAYLOAD_DIR/bin:$PATH"
export PYTHONPATH="$PAYLOAD_DIR/lib:$PAYLOAD_DIR:$PYTHONPATH"
export LD_LIBRARY_PATH="/mmc/usr/lib:$PAYLOAD_DIR/lib:$PAYLOAD_DIR:$LD_LIBRARY_PATH"
export CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1
export RAGNAR_PAGER_MODE=1
#
# Check for Python3 and python3-ctypes - required system dependencies
#
NEED_PYTHON=false
NEED_CTYPES=false
if ! command -v python3 >/dev/null 2>&1; then
NEED_PYTHON=true
NEED_CTYPES=true
elif ! python3 -c "import ctypes" 2>/dev/null; then
NEED_CTYPES=true
fi
if [ "$NEED_PYTHON" = true ] || [ "$NEED_CTYPES" = true ]; then
LOG ""
LOG "red" "=== MISSING REQUIREMENT ==="
LOG ""
if [ "$NEED_PYTHON" = true ]; then
LOG "Python3 is required to run Ragnar."
else
LOG "Python3-ctypes is required to run Ragnar."
fi
LOG "All other dependencies are bundled."
LOG ""
LOG "green" "GREEN = Install dependencies (requires internet)"
LOG "red" "RED = Exit"
LOG ""
while true; do
BUTTON=$(WAIT_FOR_INPUT 2>/dev/null)
case "$BUTTON" in
"GREEN"|"A")
LOG ""
LOG "Updating package lists..."
opkg update 2>&1 | while IFS= read -r line; do LOG " $line"; done
LOG ""
LOG "Installing Python3 + ctypes to MMC..."
opkg -d mmc install python3 python3-ctypes 2>&1 | while IFS= read -r line; do LOG " $line"; done
LOG ""
if command -v python3 >/dev/null 2>&1 && python3 -c "import ctypes" 2>/dev/null; then
LOG "green" "Python3 installed successfully!"
sleep 1
else
LOG "red" "Failed to install Python3"
LOG "red" "Check internet connection and try again."
LOG ""
LOG "Press any button to exit..."
WAIT_FOR_INPUT >/dev/null 2>&1
exit 1
fi
break
;;
"RED"|"B")
LOG "Exiting."
exit 0
;;
esac
done
fi
#
# Check nmap dependency
#
check_dependencies() {
_log "Checking dependencies..."
if ! command -v nmap >/dev/null 2>&1; then
LOG ""
LOG "red" "nmap not found. Installing..."
opkg update 2>&1 | while IFS= read -r line; do LOG " $line"; done
opkg -d mmc install nmap 2>&1 | while IFS= read -r line; do LOG " $line"; done
if ! command -v nmap >/dev/null 2>&1; then
LOG "red" "ERROR: nmap installation failed!"
LOG "Press any button to exit..."
WAIT_FOR_INPUT >/dev/null 2>&1
exit 1
fi
fi
_log green "All dependencies found!"
}
#
# Pre-flight: Validate Python can import critical modules BEFORE stopping pineapple
#
preflight_python() {
_log "Running Python pre-flight checks..."
local result
result=$(python3 -c "
import sys, os
sys.path.insert(0, os.path.join('$PAYLOAD_DIR', 'lib'))
sys.path.insert(0, '$PAYLOAD_DIR')
errors = []
try:
from pagerctl import Pager
except Exception as e:
errors.append(f'pagerctl: {e}')
try:
import json, threading, time, subprocess, signal
except Exception as e:
errors.append(f'stdlib: {e}')
try:
import shared
except Exception as e:
errors.append(f'shared: {e}')
if errors:
print('FAIL:' + '|'.join(errors))
sys.exit(1)
else:
print('OK')
sys.exit(0)
" 2>&1)
if [ $? -ne 0 ]; then
LOG ""
LOG "red" "=== PRE-FLIGHT FAILED ==="
LOG "red" "Python module import errors:"
echo "$result" | while IFS= read -r line; do
LOG "red" " $line"
echo "$line" >> "$LOG_FILE"
done
LOG ""
LOG "Check $LOG_FILE for details."
LOG "Press any button to exit..."
WAIT_FOR_INPUT >/dev/null 2>&1
exit 1
fi
_log "Pre-flight OK"
}
# ============================================================
# DISPLAY TAKEOVER & CLEANUP
# ============================================================
take_over_display() {
_log "Taking over display from pineapple service..."
# Stop the pager service cleanly via init.d (same approach as Bjorn)
/etc/init.d/pineapplepager stop 2>/dev/null
sleep 0.5
# If it's still running, force kill (fallback)
if pgrep -x pineapple >/dev/null 2>&1; then
_log "Service still running, force killing..."
killall -9 pineapple 2>/dev/null
killall -9 pineapd 2>/dev/null
sleep 0.3
fi
_log green "Display takeover complete"
}
cleanup() {
_log "Cleanup: restarting pineapplepager service..."
# Restart pager service so the normal Pager UI comes back
if ! pgrep -x pineapple >/dev/null 2>&1; then
/etc/init.d/pineapplepager start 2>/dev/null
fi
}
# Ensure pager service restarts on exit
trap cleanup EXIT
# ============================================================
# MAIN
# ============================================================
check_dependencies
# Check network connectivity (at least one interface with IP)
HAS_NETWORK=false
for IP in $(ip -4 addr 2>/dev/null | grep 'inet ' | awk '{print $2}' | cut -d/ -f1); do
if [ "$IP" != "127.0.0.1" ]; then
HAS_NETWORK=true
break
fi
done
if [ "$HAS_NETWORK" = false ]; then
LOG ""
LOG "red" "=== NO NETWORK CONNECTED ==="
LOG ""
LOG "Ragnar requires a network connection to scan."
LOG "Please connect to a network first:"
LOG " - WiFi client mode (wlan0cli)"
LOG " - Ethernet/USB (br-lan)"
LOG ""
LOG "Press any button to exit..."
WAIT_FOR_INPUT >/dev/null 2>&1
exit 1
fi
# Pre-flight Python check (while pineapple is still alive so errors show on LCD)
preflight_python
# Show splash screen
LOG ""
LOG "green" "Ragnar"
LOG "cyan" "https://github.com/PierreGode/Ragnar"
LOG ""
LOG "yellow" "Features:"
LOG "cyan" " - Automated network reconnaissance"
LOG "cyan" " - Port scanning with nmap"
LOG "cyan" " - SSH/SMB/FTP/Telnet/RDP/SQL brute force"
LOG "cyan" " - File stealing and data exfiltration"
LOG "cyan" " - Vulnerability scanning"
LOG "cyan" " - Web UI for monitoring"
LOG ""
LOG "green" "GREEN = Start"
LOG "red" "RED = Exit"
LOG ""
while true; do
BUTTON=$(WAIT_FOR_INPUT 2>/dev/null)
case "$BUTTON" in
"GREEN"|"A")
break
;;
"RED"|"B")
LOG "Exiting."
exit 0
;;
esac
done
# Take over the LCD from the pineapple service.
# Must kill pineapple (UI) + pineapd (PineAP) + deregister from procd.
LOG "Starting Ragnar..."
take_over_display
sleep 0.3
# Payload loop with handoff support
# Python writes the target launch script path to data/.next_payload
NEXT_PAYLOAD_FILE="$DATA_DIR/.next_payload"
while true; do
cd "$PAYLOAD_DIR"
_log "Launching pager_menu.py..."
python3 pager_menu.py >> "$LOG_FILE" 2>&1
EXIT_CODE=$?
_log "pager_menu.py exited with code $EXIT_CODE"
# Exit code 42 = hand off to another payload
if [ "$EXIT_CODE" -eq 42 ] && [ -f "$NEXT_PAYLOAD_FILE" ]; then
NEXT_SCRIPT=$(cat "$NEXT_PAYLOAD_FILE")
rm -f "$NEXT_PAYLOAD_FILE"
if [ -f "$NEXT_SCRIPT" ]; then
_log "Handing off to $NEXT_SCRIPT"
sh "$NEXT_SCRIPT"
# Only loop back to Ragnar if launched app exits 42
[ $? -eq 42 ] && continue
fi
fi
# Exit code 99 = return to main menu (from pause menu)
if [ "$EXIT_CODE" -eq 99 ]; then
_log "Returning to menu (exit code 99)"
continue
fi
# If pager_menu.py crashed, log it
if [ "$EXIT_CODE" -ne 0 ]; then
_log red "pager_menu.py failed (exit $EXIT_CODE)"
fi
break
done
exit 0