From 12899ada3975b5555bf563bb3cc90c36db18512b Mon Sep 17 00:00:00 2001 From: happybell80 Date: Tue, 26 Aug 2025 14:52:47 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20=EB=B3=B4=EC=95=88=20=EA=B3=B5=EA=B2=A9?= =?UTF-8?q?=20=ED=83=90=EC=A7=80=20=EB=B0=8F=20=EB=8C=80=EC=9D=91=20?= =?UTF-8?q?=EB=B0=A9=EC=95=88=20=EB=AC=B8=EC=84=9C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PHPUnit RCE 및 .env 탈취 시도 분석 - 공격자 IP 목록 및 패턴 정리 - iptables, fail2ban, nginx 보안 설정 방안 - 모니터링 및 장기 대책 포함 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../250826_security_attack_detection.md | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 troubleshooting/250826_security_attack_detection.md diff --git a/troubleshooting/250826_security_attack_detection.md b/troubleshooting/250826_security_attack_detection.md new file mode 100644 index 0000000..d658079 --- /dev/null +++ b/troubleshooting/250826_security_attack_detection.md @@ -0,0 +1,190 @@ +# 보안 공격 탐지 및 대응 + +## 작성일: 2025-08-26 +## 작성자: 서버 관리자 +## 상태: 대응 진행중 +## 영향: 51123 서버 대상 자동화 공격 + +--- + +## 1. 공격 탐지 내역 + +### 1.1 발견 경위 +- Frontend 컨테이너 로그에서 의심스러운 접근 시도 발견 +- PHPUnit eval-stdin.php 및 .env 파일 접근 시도 + +### 1.2 공격 유형 +| 공격 유형 | 대상 파일 | 목적 | +|----------|----------|------| +| PHPUnit RCE | `/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php` | 원격 코드 실행 | +| 환경변수 탈취 | `/.env`, `/api/.env` | 비밀번호/API키 획득 | + +--- + +## 2. 공격자 IP 분석 + +### 2.1 주요 공격 IP (nginx access.log 분석) +| IP 주소 | 공격 횟수 | 공격 유형 | 최근 활동 | +|---------|-----------|----------|-----------| +| 185.177.72.10 | 142회 | 복합 스캔 | 활성 | +| 119.8.169.21 | 74회 | 자동화 스캔 | 활성 | +| 111.119.234.186 | 74회 | 자동화 스캔 | 활성 | +| 103.225.9.122 | 37회 | PHPUnit 전용 | 8/25 06:17 | +| 142.93.90.55 | 다수 | .env 스캔 | 8/26 12:39 | +| 8.213.41.158 | 12회 | .env 스캔 | 8/25 23:00 | +| 185.177.72.29 | 다수 | .env 스캔 | 8/26 10:44 | + +### 2.2 공격 패턴 +```bash +# PHPUnit 공격 패턴 (103.225.9.122) +[25/Aug/2025:06:17:24] /workspace/drupal/vendor/phpunit/... +[25/Aug/2025:06:17:25] /panel/vendor/phpunit/... +[25/Aug/2025:06:17:26] /public/vendor/phpunit/... +[25/Aug/2025:06:17:27] /apps/vendor/phpunit/... +[25/Aug/2025:06:17:28] /app/vendor/phpunit/... + +# .env 스캔 패턴 (142.93.90.55) +[26/Aug/2025:05:45:37] /.env +[26/Aug/2025:12:39:21] /.env (반복) +``` + +--- + +## 3. 현재 방어 상태 + +### 3.1 자동 방어 (이미 작동중) +- ✅ 404 응답 반환 (취약 파일 없음) +- ✅ Python/FastAPI 환경 (PHP 취약점 영향 없음) +- ✅ Docker 컨테이너 격리 + +### 3.2 추가 필요 조치 +- ❌ IP 차단 규칙 미설정 +- ❌ fail2ban 미구성 +- ❌ WAF 규칙 미적용 + +--- + +## 4. 대응 조치 계획 + +### 4.1 즉시 차단 (iptables) +```bash +# 주요 공격 IP 차단 +sudo iptables -A INPUT -s 185.177.72.10 -j DROP +sudo iptables -A INPUT -s 119.8.169.21 -j DROP +sudo iptables -A INPUT -s 111.119.234.186 -j DROP +sudo iptables -A INPUT -s 103.225.9.122 -j DROP +sudo iptables -A INPUT -s 142.93.90.55 -j DROP +sudo iptables -A INPUT -s 8.213.41.158 -j DROP +sudo iptables -A INPUT -s 185.177.72.29 -j DROP + +# 규칙 저장 (재부팅 후에도 유지) +sudo apt-get install iptables-persistent +sudo netfilter-persistent save +``` + +### 4.2 fail2ban 설정 +```bash +# fail2ban 설치 +sudo apt-get install fail2ban + +# nginx 보안 필터 생성 +sudo cat > /etc/fail2ban/filter.d/nginx-security.conf << 'EOF' +[Definition] +failregex = ^ .* "(GET|POST) .*(phpunit|eval-stdin|\.env).*" .*$ +ignoreregex = +EOF + +# jail 설정 +sudo cat > /etc/fail2ban/jail.d/nginx-security.conf << 'EOF' +[nginx-security] +enabled = true +filter = nginx-security +logpath = /var/log/nginx/access.log +maxretry = 3 +bantime = 86400 +findtime = 3600 +action = iptables-multiport[name=nginx-security, port="http,https"] +EOF + +# fail2ban 재시작 +sudo systemctl restart fail2ban +``` + +### 4.3 nginx 보안 헤더 강화 +```nginx +# /etc/nginx/snippets/security.conf +location ~ \.(env|git|svn|htaccess|htpasswd)$ { + deny all; + return 404; +} + +location ~ /(vendor|phpunit|eval-stdin)/ { + deny all; + return 404; +} + +# 보안 헤더 추가 +add_header X-Frame-Options "SAMEORIGIN" always; +add_header X-Content-Type-Options "nosniff" always; +add_header X-XSS-Protection "1; mode=block" always; +``` + +--- + +## 5. 모니터링 명령어 + +### 5.1 실시간 공격 모니터링 +```bash +# 실시간 공격 시도 감시 +tail -f /var/log/nginx/access.log | grep -E "phpunit|eval-stdin|\.env" + +# 공격 IP 통계 +sudo grep -E "phpunit|\.env" /var/log/nginx/access.log.1 | \ + awk '{print $1}' | sort | uniq -c | sort -rn | head -20 + +# fail2ban 차단 목록 +sudo fail2ban-client status nginx-security +``` + +### 5.2 차단 확인 +```bash +# iptables 규칙 확인 +sudo iptables -L -n -v | grep DROP + +# 차단된 IP 연결 시도 +sudo tcpdump -i any src host 185.177.72.10 +``` + +--- + +## 6. 장기 대책 + +### 6.1 보안 강화 +1. **CloudFlare/WAF 도입 검토** + - DDoS 방어 + - 자동 봇 차단 + - 지역 기반 접근 제한 + +2. **로그 분석 자동화** + - ELK Stack 구축 + - 이상 패턴 자동 알림 + +3. **정기 보안 점검** + - 월 1회 로그 분석 + - 분기별 보안 감사 + +### 6.2 대응 프로세스 +1. 공격 탐지 → 2. IP 분석 → 3. 즉시 차단 → 4. 패턴 분석 → 5. 규칙 업데이트 + +--- + +## 7. 참고 사항 + +- 공격은 자동화 봇에 의한 대규모 스캔 +- 실제 침투 성공 사례 없음 +- Docker 환경으로 격리되어 영향 최소화 +- 정기적인 로그 검토 필요 + +--- + +*작성 완료: 2025-08-26 15:00* \ No newline at end of file