Showing posts with label hooking. Show all posts
Showing posts with label hooking. Show all posts

# ashell: Proxy chaining hooking connect()


Introduction

Anonymous shell (ashell) is a tool to tunnel your connections through HTTP/Socks4/Socks5 proxies.
Supports TCP, authentication and chaining different proxy types.
It works by hooking the connect() function using LD_PRELOAD environment variable.

http://sourceforge.net/projects/ashell/


Building and using the tool

# apt-get install libssl-dev
# wget http://downloads.sourceforge.net/project/ashell/ashell-0.3.tar.bz2
# tar xvjf ashell-0.3.tar.bz2
# cd ashell-0.3
# cat README
# cp ashell/ashell.c .
# cat > Makefile << "EOF"
> HEADERS = http.h socks.h strlib.h
> OBJECTS = http.o socks.o strlib.o ashell.o
> CFLAGS = -Wall
> LFLAGS = -ldl -shared -nostartfiles -fpic
>
> default: ashell.so
>
> %.o: %.c $(HEADERS)
> #gcc -o $@ -c $<
>
> ashell.so: $(OBJECTS)
> #gcc -o $@ $(CFLAGS) $(LFLAGS) $(OBJECTS)
>
> clean:
> #rm -rf $(OBJECTS)
> EOF
# sed -i 's/#/\t/' Makefile
# make
# curl -w "\nTime total=%{time_total}\n" whatismyip.akamai.com
1.2.3.4
Time total=0,058
# export P_DEBUG=0 # P_DEBUG=1 turns on debugging
# export LD_PRELOAD=./ashell.so
# export APROXY=S:89.28.65.46:1080+S:86.127.123.141:18060
# curl -w "\nTime total=%{time_total}\n" whatismyip.akamai.com
86.127.123.141
Time total=3,323


Socks5 open proxy list

http://spys.ru/en/socks-proxy-list/


# LD_PRELOAD hooking


# grep -m 1 localtime /usr/include/time.h
extern struct tm *localtime (__const time_t *__timer) __THROW;
# cat newdate.c
#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
#include <dlfcn.h>

struct tm *(*orig_localtime)(const time_t *timep);

struct tm *localtime(const time_t *timep){
        time_t t=946684860;
        return orig_localtime(&t);
}

void _init(void){
        orig_localtime=dlsym(RTLD_NEXT,"localtime");
}
# gcc -Wall -fPIC -o newdate.o -c newdate.c
# ld -shared -o newdate.so newdate.o -ldl
# date
Thu Jan 10 13:35:30 CET 2013
# LD_PRELOAD=./newdate.so date
Sat Jan  1 01:01:00 CET 2000