victim 에서 작성
(victim = 192.168.108.100/24)
Victim ~# systemctl stop firewalld
Victim ~# systemctl disable firewalld
Victim ~# yum -y install iptables-services
Victim ~# iptables -F
Victim ~# iptables-save > /etc/sysconfig/iptables
Victim ~# vi dropip.sh
| -- dropip.sh -- #!/bin/sh # 파일명 : dropip.sh # 프로그램 설명 : 쉘스크립트를 이용한 자동화된 공격IP 차단 룰 생성 프로그램 # 업데이트 : 2021.12.28 # 버전 : 0.2 # 작성자 : linuxmaster.net ADMINIP="192.168.108.1" IPTABLES=/sbin/iptables IPTABLE_CHAIN=DROPIP IPTABLE_CHAIN2=ACCEPTIP # 사용자 정의 체인 DROPIP를 생성한다. $IPTABLES -N $IPTABLE_CHAIN > /dev/null 2>&1 $IPTABLES -N $IPTABLE_CHAIN2 > /dev/null 2>&1 # 관리자 IP주소를 ACCEPTIP 체인에 등록한다. $IPTABLES -A ACCEPTIP -s $ADMINIP -j ACCEPT # INPUT 체인에 ACCEPTIP를 검사한다. iptables -nL INPUT | grep -q ACCEPTIP if [ $? -ne 0 ] # ACCEPTIP가 없다면 then # INPUT 체인에 ACCEPTIP를 등록한다. $IPTABLES -A INPUT -j ACCEPTIP fi # INPUT 체인에 DROPIP를 검사한다. iptables -nL INPUT | grep -q DROPIP if [ $? -ne 0 ] # DROPIP가 없다면 then # INPUT 체인에 DROPIP를 등록한다. $IPTABLES -A INPUT -j DROPIP fi # /var/log/secure 로그 파일에서 공격자 IP주소를 검색한다. BLOCKIP=$(grep 'Failed password for invalid user' /var/log/secure | awk '{print $13}' | sort | uniq) for attackip in $BLOCKIP do # 디버깅 # echo $attackip if [ $attackip = "::1" ]; then continue fi # 관리자 IP주소이면 방화벽에 등록하지 않는다. if [ $attackip = $ADMINIP ]; then continue fi $IPTABLES -nL $IPTABLE_CHAIN | grep -q $attackip if [ $? -ne 0 ] # != then #echo $IPTABLES -A $IPTABLE_CHAIN -s $attackip -j DROP $IPTABLES -A $IPTABLE_CHAIN -s $attackip -j DROP else echo "$attackip 방화벽에 이미 등록됨" fi done -- dropip.sh -- |
chmod 755 dropip.sh
./dropip.sh
룰의 흐름 INPUT -> DROPIP -> INPUT
victim 에서 작성 [반복문X]
Victim ~# mkdir bin
Victim ~# mv dropip.sh bin
Victim ~# dropip.sh
방화벽을 확인해서 아래처럼 IP주소가 등록되면 성공이다.
Victim ~# iptables -nL
| Chain INPUT (policy ACCEPT) target prot opt source destination DROPIP all -- 0.0.0.0/0 0.0.0.0/0 Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain DROPIP (2 references) target prot opt source destination DROP all -- 192.168.108.102 0.0.0.0/0 Victim ~# |
Kali 에서 접속하려 하면 접속이 안된다.
Attacker \h \W$ ssh user1@192.168.108.100 130 ⨯
...
'Linux > 모의해킹' 카테고리의 다른 글
| [Kali] dropip.sh 파일을 cron 에 등록하기 (0) | 2021.12.28 |
|---|---|
| [Kali] 공격자 IP 주소 추가하기 (0) | 2021.12.28 |
| [Kali] hydra 무차별 대입 공격 (0) | 2021.12.28 |
| tracert 를 이용한 경로 추적하기 (0) | 2021.12.28 |
| [Kali] Port Scan 포트 스캔 (0) | 2021.12.28 |