Iptables에서는 체인이라고 하는 규칙 목록이 순차적으로 처리됩니다. 이 중에서 세 가지 주요 체인이 모든 시스템에서 일반적으로 존재하며, NAT와 같은 추가 체인은 시스템의 기능에 따라 지원될 수 있습니다.
Input Chain: 들어오는 연결의 동작을 관리하는 데 사용됩니다.
Forward Chain: 로컬 시스템으로 가지 않는 들어오는 연결을 처리하는 데 사용됩니다. 이는 라우터로 작동하는 장치에서 일반적으로 발생하며, 받은 데이터를 다른 대상으로 전달해야 하는 경우에 해당합니다. 이 체인은 주로 시스템이 라우팅, NAT 또는 유사한 활동에 참여할 때 중요합니다.
Output Chain: 나가는 연결의 규제에 전념합니다.
이러한 체인은 네트워크 트래픽의 정돈된 처리를 보장하며, 시스템으로 데이터의 흐름을 상세하게 규정하는 규칙을 지정할 수 있게 합니다.
# Delete all rulesiptables-F# List all rulesiptables-Liptables-S# Block IP addresses & portsiptables-IINPUT-sip1,ip2,ip3-jDROPiptables-IINPUT-ptcp--dport443-jDROPiptables-IINPUT-sip1,ip2-ptcp--dport443-jDROP# String based drop## Strings are case sensitive (pretty easy to bypass if you want to check an SQLi for example)iptables-IINPUT-ptcp--dport<port_listening>-mstring--algobm--string'<payload>'-jDROPiptables-IOUTPUT-ptcp--sport<port_listening>-mstring--algobm--string'CTF{'-jDROP## You can also check for the hex, base64 and double base64 of the expected CTF flag chars# Drop every input port except someiptables-PINPUTDROP# Default to dropiptables-IINPUT-ptcp--dport8000-jACCEPTiptables-IINPUT-ptcp--dport443-jACCEPT# Persist Iptables## Debian/Ubuntu:apt-getinstalliptables-persistentiptables-save>/etc/iptables/rules.v4ip6tables-save>/etc/iptables/rules.v6iptables-restore</etc/iptables/rules.v4##RHEL/CentOS:iptables-save>/etc/sysconfig/iptablesip6tables-save>/etc/sysconfig/ip6tablesiptables-restore</etc/sysconfig/iptables
Suricata
설치 및 설정
To install Suricata, follow these steps:
Update the package manager: sudo apt update
Install Suricata: sudo apt install suricata
Configure Suricata by editing the configuration file located at /etc/suricata/suricata.yaml.
Suricata 설치 및 설정
Suricata를 설치하려면 다음 단계를 따르십시오:
패키지 관리자를 업데이트합니다: sudo apt update
Suricata를 설치합니다: sudo apt install suricata
/etc/suricata/suricata.yaml에 위치한 구성 파일을 편집하여 Suricata를 구성합니다.
# Install details from: https://suricata.readthedocs.io/en/suricata-6.0.0/install.html#install-binary-packages# Ubuntuadd-apt-repositoryppa:oisf/suricata-stableapt-getupdateapt-getinstallsuricata# Debianecho"deb http://http.debian.net/debian buster-backports main"> \/etc/apt/sources.list.d/backports.listapt-getupdateapt-getinstallsuricata-tbuster-backports# CentOSyuminstallepel-releaseyuminstallsuricata# Get rulessuricata-updatesuricata-updatelist-sources#List sources of the rulessuricata-updateenable-sourceet/open#Add et/open rulesetssuricata-update## To use the dowloaded rules update the following line in /etc/suricata/suricata.yamldefault-rule-path:/var/lib/suricata/rulesrule-files:-suricata.rules# Run## Add rules in /etc/suricata/rules/suricata.rulessystemctlsuricatastartsuricata-c/etc/suricata/suricata.yaml-ieth0# Reload rulessuricatasc-cruleset-reload-nonblocking## or set the follogin in /etc/suricata/suricata.yamldetect-engine:-rule-reload:true# Validate suricata configsuricata-T-c/etc/suricata/suricata.yaml-v# Configure suricata as IPs## Config drop to generate alerts## Search for the following lines in /etc/suricata/suricata.yaml and remove comments:-drop:alerts:yesflows:all## Forward all packages to the queue where suricata can act as IPSiptables-IINPUT-jNFQUEUEiptables-IOUTPUT-jNFQUEUE## Start suricata in IPS modesuricata-c/etc/suricata/suricata.yaml-q0### or modify the service config file as:systemctleditsuricata.service[Service]ExecStart=ExecStart=/usr/bin/suricata-c/etc/suricata/suricata.yaml--pidfile/run/suricata.pid-q0-vvvType=simplesystemctldaemon-reload
Suricata에는 수백 가지의 옵션이 있어 원하는 특정 패킷을 검색할 수 있습니다. 여기서는 흥미로운 내용이 발견되면 언급될 것입니다. 자세한 내용은 문서를 확인하세요!
# Meta Keywordsmsg:"description"; #Set a description to the rulesid:123#Set a unique ID to the rulerev:1#Rule revision numberconfigclassification:not-suspicious,NotSuspiciousTraffic,3#Classifyreference:url,www.info.com#Referencepriority:1; #Set a prioritymetadata:keyvalue,keyvalue; #Extra metadata# Filter by geolocationgeoip:src,RU;# ICMP type & Codeitype:<10;icode:0# Filter by stringcontent:"something"content:|616161|#Hex: AAAcontent:"http|3A|//"#Mix string and hexcontent:"abc"; nocase; #Case insensitiverejecttcpanyany ->anyany (msg: "php-rce"; content:"eval"; nocase; metadata:tagphp-rce; sid:101; rev:1;)# Replaces string## Content and replace string must have the same lengthcontent:"abc"; replace:"def"alerttcpanyany ->anyany (msg: "flag replace"; content:"CTF{a6st"; replace:"CTF{u798"; nocase; sid:100; rev:1;)## The replace works in both input and output packets## But it only modifies the first match# Filter by regexpcre:"/<regex>/opts"pcre:"/NICK .*USA.*[0-9]{3,}/i"droptcpanyany ->anyany (msg:"regex"; pcre:"/CTF\{[\w]{3}/i"; sid:10001;)# Other examples## Drop by portdroptcpanyany ->any8000 (msg:"8000 port"; sid:1000;)
htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!
사이버 보안 회사에서 일하시나요? 회사를 HackTricks에서 광고하고 싶으신가요? 아니면 PEASS의 최신 버전에 액세스하거나 HackTricks를 PDF로 다운로드하고 싶으신가요? SUBSCRIPTION PLANS를 확인해보세요!