/be-a-red-teamer

Learn how to be a red teamer while summing up related notes.

MIT LicenseMIT

Inventory

License Repo Size Activity zhsh9 GitHub stars

Red Team Kill Chain:

┌────────────────┐
│                │
│   Initial      │
│   Recon        │
│                │
└────────┬───────┘
         │
         │
┌────────▼───────┐
│                │
│   Initial      │
│   Compromise   │
│                │
└────────┬───────┘
         │
         │
┌────────▼───────┐
│                │
│   Establish    │
│   Foothold     │
│                │
└────────┬───────┘
         │
         │
┌────────▼───────┐      ┌────────────────┐
│                │      │                │
│   Escalte      ◄──────┤   Maintain     │
│   Privileges   │      │   Presence     │
│                │      │                │
└────────┬───────┘      └────────▲───────┘
         │                       │
         │                       │
┌────────▼───────┐      ┌────────┴───────┐
│                │      │                │
│   Internal     │      │   Move         │
│   Recon        ├──────►   Laterally    │
│                │      │                │
└────────┬───────┘      └────────────────┘
         │
         │
┌────────▼───────┐
│                │
│   Complete     │
│   Mission      │
│                │
└────────────────┘

0. 前置知识 Background

0.1 操作系统使用

OS:

  • Linux
  • Windows
    • Win Servers
    • Win7
    • Win10
    • Win11
  • macOS

Integrated Pentest Environment:

  • Exegol on macOS, 👉🏻GO
  • Kali Linux VM, PD on macOS
  • Kali Linux VM, OrbStack on macOS

0.2 Shell使用

0.3 Web三剑客

  • HTML
  • CSS
  • JS

0.4 编程语言

主流:

其他:

  • Lua
  • Perl
  • Ruby

0.5 数据库

  • SQL
  • NoSQL
    • Redis
    • MongoDB
    • ElasticSearch

0.6 协议

  • HTTP
  • HTTPS
  • DHCP
  • DNS
  • SSH
  • ARP
  • SMB
  • Socks5
  • VPN
  • FTP
  • ...

0.7 二进制

  • Assembly, 👉🏻Go
  • Reverse Engineering, x86_64
    • Basic: C/C++
    • Windows Platform
    • Linux PLatform

0.8 效率工具

0.9 渗透工具

1. 信息收集 Reconnaissance

      subdomain  top-domain-level    signifies query
        ───        ───                   ──
https://sub.domain.com/blog/article/search?param=1
──────      ──────     ─────────────────── ───────
scheme      domain      path or location   parameter(s)
                             of contents

Social Engineer

Generate word list:

Banner Grabbing

# 扫描端口,然后探测版本(用默认的脚本)
nmap -n -v -Pn -sS -p- $IP --max-retries=0
nmap -n -v -sC -sV -p$PORTS $IP
# 
nmap -sn $IP/24                   # 寻找IP
nmap -sT --min-rate 10000 -p- $IP
nmap -sU --min-rate 10000 -p- $IP # TCP|UDP扫描全端口
nmap -sT -sV -sC -O -p$PORTS $IP  # TCP使用默认脚本扫描全端口+版本+OS信息
nmap --script-vuln -p$PORTS $IP   # 漏洞脚本扫描
# 一句话全模式扫描开放端口
nmap -A $IP -oA nmap/all -p`nmap -sS -sU -Pn -p- $IP --min-rate 10000 | grep '/tcp\|/udp' | awk -F '/' '{print $1}' | sort -u | tr '\n' ','`

Host and Port

  • nmap
nmap -sn $IP/24
nmap -sU --min-rate 10000 -p- $IP
nmap -sT -sC -sV -O --min-rate 10000 -p- $IP
nmap --script=vuln -p$PORTS $IP
  • ping 主机发现
ping -c 3 -W 1 $IP
for i in {1..254}; do ping -c 1 -W 1 $sub_IP.$i | grep from; done
  • nc 端口扫描
nc.traditional -vv -z $IP 1-65535 2>&1 | grep -v refused
  • /dev/tcp/xxx/nnn 端口扫描
IP=xxx.xxx.xxx.xxx
for i in {1..65535}
do
    (echo < /dev/tcp/$IP/$i) &>/dev/null && printf "\n[+] Open port: %d\n" "$i" || printf "."
done

web scanner

whatweb [opts] <urls>

web path

dirb $IP $Wordlist
  • dirsearch
    • -t <thead>
    • -r, brute-force recursively
    • -i <code>, include status codes
    • -x <codes>, exclude status codes
    • -m <method>
    • -d <data>
    • -H <headers>
    • --user-agent=<ua>
    • --cookie=<ck>
dirsearch -u <target> -e <extensions> [options]
ffuf -fs 185 -c -w \$(fzf-wordlists) -H 'Host: FUZZ.org' -u "http://$TARGET/"
ffuf -w /usr/share/dirb/wordlists/common.txt -fc 403,404 -fs 185 -u "http://$TARGET/FUZZ" -p 1

IPv6 Scan

  • nmap
nmap -6 --min-rate 10000 -p- $IPv6
python IOXIDResolver.py -t $IP
snmpwalk -v2c -c public $IP

OS

  • 有web端:
    • Windows大小写不敏感
    • 工具识别
  • 没有web:
    • nmap -O
  • TTL(不准确的方式):
1、WINDOWS NT/2000   TTL:128
2、WINDOWS 95/98     TTL:32
3、UNIX              TTL:255
4、LINUX             TTL:64
5、WIN7         	    TTL:64
  • 特殊端口:22, 139, 445, 1433, 3389

Database

数据库不同表示的结构也是不同、写法结构也不同,因此产生的漏洞也不一样。不同的数据库的攻击方式也不完全一样。

  • default pair
    1. asp + access/mssql
    2. php + mysql
    3. aspx + mssql
    4. jsp + mysql/oracle
    5. python + mongodb
  • common port
    • SQL
      • mysql, 3306
      • sqlserver, 1433
      • oracle, 1521
      • postgresql, 5432
    • NoSQL
      • mongodb, 27017
      • redis, 6379
      • memcached, 11211

DNS

  • dig
  • nslookup
  • whois
dig axfr mydomain.local @IP_ADRESS
nslookup -type=any $DOMAIN_NAME
whois $DOMAIN_NAME
theHarvester -d $DOMAIN_NAME -b google

CDN

CDN: Content Dilivery Network

WAF

WAF: Web Application Firewall

  • objective
    • 没有识别WAF直接扫描可能导致IP黑名单
    • 识别完具体的WAF可以有针对性的bypass
  • recognize WAF
    • waf00f
    • identYwaf
    • nmap
      • nmap --script=http-waf-fingerprint
      • nmap --script=http-waf-detec
    • 有些Web站点会在GET Header中遗留WAF相关信息

Web源码

  • 目录结构
    • 后台目录
    • 模板目录
    • 数据库目录
    • 数据库配置文件
  • 脚本类型
    • asp
    • php
    • jsp
    • java
  • 应用分类
    • 门户
    • 电商
    • 论坛
    • 博客
  • 其他补充
    • 框架or非框架
    • CMS识别
    • 开源or闭源
    • 源码获取

Subdomain

  • gobuster
# fzf-wordlists
/usr/share/seclists/Discovery/DNS/subdomains-top1million-110000.txt
# gobuster
gobuster vhost -u <http://example.com> -w /path/to/wordlist.txt --append-domain -t $THREAD_NUM

站点搭建

  1. 目录型站点(例如,www.xxx.com/bbs
    • 主站的漏洞
    • 子站的漏洞
  2. 端口类站点,shodan扫描
  3. 子域名站点(子域名和域名可能不在一个服务器上)
  4. 类似域名站点(原有域名弃用,但是还能访问;二级or顶级域名更换,旧域名找到突破口)
    • 社工方式找到相关域名信息
  5. 旁注,C段站点(在线工具:https://www.webscan.cc/)
    1. 旁注:同一个服务器上面存在多个站点、但是你要攻击的是A网站由于各种原因不能完成安全测试。就通过测试B网站进入服务器然后在攻击A网站最终实现目的。
    2. C段:不同的服务器上面存在不同的网站,通过扫描发现与你渗透测试的是同一个网段最终拿下服务器、然后通过内网渗透的方式拿下渗透服务器。
  6. 搭建软件特征站点
    • 有的网站是借助于第三方的集成搭建工具实现例如:PHPstudy、宝塔等环境这样的集成环境搭建的危害就是泄露了详细的版本信息。
    • phpstudy搭建了之后在默认的站点安装了phpmyadmin有的网站没有做安全性直接可以通过用户名:root密码:root 登录进入

资产收集

  • GitHub
  • 搜集:子域名、DNS、备案、证书、全球节点请求CDN
  • 搜索引擎:fofa, shodan, zoomeye

2. 漏洞挖掘 Vulnerabilities

Command Injection

SQLi

File Upload

XSS

CSRF

Deserialization

Payment

WAF & Bypass

Code Audit

3. 权限提升 Privilege Escalation

主流

  • UGO
  • SUID, SGID
  • Capabilities
  • AppArmor, Selinux
  • ACL

其他

  • Grsecurity
  • Pax
  • ExecShield
  • ASLR
  • TOMOYO Linux
  • SMACK
  • Yama
  • CGroups
  • Linux Namespaces
  • StackGuard
  • Proplice
  • seccomp
  • ptrace
  • capsicum
  • Mprotect
  • chroot
  • firejail

靠山吃山,靠水吃水

生产password密码 (qwe~qwe)

openssl passwd -1 -salt qwe qwe > hash.txt # generate a user line
echo 'qwe:$1$qwe$D95bkH3CwpH6ffYU7pu0m/:0:0:root:/root:/bin/bash' >> /etc/passwd # Append this line into passwd file

3.0 Shells

3.1 提权原理总结

  1. 低权限可以修改可执行文件or脚本,再以高权限身份运行;
  2. 低权限的运维人员也会记录、输入备份程序,以备使用高权限的时候完成操作(用户行为);
  3. 在权限体系的上层捕捉、拦截、修改凭据信息or权限信息。

3.2 手工枚举

  • 系统枚举
    • 用户信息
      • whoami
      • id
      • who
      • w
      • last
    • 系统信息
      • uname -a
      • lsb_release -a
      • cat /proc/version
      • cat /etc/issue
      • hostnamectl
  • 网络枚举
    • ifconfig
    • ip
      • ip a
      • ip route
      • ip neigh
    • netstat
      • netstat -a
      • netstat -at (-au)
      • netstat -l
      • netstat -s
      • netstat -ano
  • 权限枚举
    • sudo -l
  • getcap -r 2>/dev/null
  • ls -liah
  • history
  • cat /etc/passwd
  • cat /etc/crontab
  • echo $PATH
  • env
  • 进程枚举
    • ps -ef, ps aux
    • ps axjf
    • top -n 1
  • find / -perm -u=s -type f 2>/dev/null
  • which awk (perl, python, ruby, gcc, vi, vim, nmap, find, netcat, nc, wget, tftp, ftp, tmux, screen ...) 2>/dev/null
  • cat /etc/fstab 磁盘挂载情况

3.3 自动枚举

工具列表

工具使用, 👉🏻GO

4. 后渗透期 Post Pentest

5. 对抗攻防 AWD

5. 社会工程 Social Engeering

6. 软件开发 Software Engeering

Appendix. 链接

👉🏻GO

Appendix. 靶场

Appendix. 书籍

  • Computer Science
    • CSAPP
    • Linux Basics for Hacker
  • Computer Languages
    • Python
      • Fluent Python
    • Go
      • Black Hat Go
  • Pentest
    • Penetration Testing with Kali Linux
    • Kali Linux Penetration Testing Bible
    • Google Hacking
    • OWASP权威指南
  • Binary
    • Intel® 64 and IA-32 Architectures Software Developer’s Manual
    • The IDA Pro Book
    • The Ghidra Book

Appendix. 学习资料