Active Information Gathering Techniques

Active Information Gathering Techniques

in

DNS Enumeration

Understanding different DNS record types is important for reconnaissance:

  • NS (Name Server): Identifies the authoritative DNS servers for a domain.
  • A (Host): Maps a hostname to an IPv4 address.
  • AAAA (IPv6 Host): Maps a hostname to an IPv6 address.
  • MX (Mail Exchanger): Specifies the mail servers responsible for handling email for the domain.
  • PTR (Pointer): Used in reverse DNS lookups to find the domain name associated with an IP address.
  • CNAME (Canonical Name): Creates an alias for another hostname.
  • TXT (Text): Allows storing arbitrary text data, often used for domain verification (e.g., SPF, DKIM).

Unix Tools:

  • host: A simple utility for DNS lookups.
    host www.example.com
    host -t mx example.com
    host -t txt example.com
    
  • DNSRecon: A more advanced Python script for DNS enumeration.
    # Standard enumeration
    dnsrecon -d example.com -t std
    # Brute-force subdomains using a wordlist
    dnsrecon -d example.com -D ~/list.txt -t brt
    
  • dnsenum: Another popular DNS enumeration script.
    dnsenum example.com
    

Windows Tools:

  • nslookup: The standard Windows command-line tool for querying DNS.
    nslookup mail.example.com
    # Query a specific record type against a specific DNS server
    nslookup -type=TXT info.example.com 192.168.1.1
    
  • net view: Can sometimes reveal information in Windows environments (though not strictly DNS).
    net view \\dc01 /all
    

Port Scanning with Netcat (nc)

While not a dedicated port scanner like Nmap, nc can be used for basic port checks. It’s often slower and less feature-rich.

Options:

  • -n: Do not resolve hostnames (faster).
  • -v/-vv: Verbose output.
  • -w <seconds>: Timeout for connections.
  • -z: Zero-I/O mode (scan without sending data).
  • -u: Scan UDP ports.

Examples:

  • Basic TCP Port Scan:
    nc -nvv -w 3 -z 192.168.212.151 1-100
    
  • Basic UDP Port Scan:
    nc -nv -u -z -w 1 192.168.50.149 120-123
    
  • Faster Scanning with Threading (using xargs):
    # TCP Scan with 20 parallel connections
    seq 1000 10000 | xargs -P 20 -I {} nc -nvv -w 1 -z 192.168.50.151 {} 2>&1 | grep "open"
    # UDP Scan with 20 parallel connections
    seq 100 200 | xargs -P 20 -I {} nc -nvv -u -w 3 -z 192.168.159.151 {} 2>&1 | grep "open"
    

Port Scanning with Nmap

Nmap is the industry standard for port scanning and network discovery.

Windows Alternatives:

  • Test-NetConnection: Built-in PowerShell cmdlet for testing network connectivity, including specific ports.
    Test-NetConnection -Port 445 192.168.50.151
    
  • PowerShell Loop for Port Scanning:
    # Scan TCP ports 1-1024
    1..1024 | % { try { $tcpClient = New-Object Net.Sockets.TcpClient; $tcpClient.Connect("192.168.50.151", $_); Write-Output "TCP port $_ is open"; $tcpClient.Close() } catch {} } 2>$null
    
    # Scan the last octet for an open port (e.g., port 43)
    1..254 | ForEach-Object {
        $ip = "192.168.50.$_"
        try {
            $tcpClient = New-Object Net.Sockets.TcpClient
            $tcpClient.Connect($ip, 43)
            if ($tcpClient.Connected) { Write-Output "TCP port 43 is open on $ip"; $tcpClient.Close() }
        } catch {}
    }
    

SMB Enumeration

Server Message Block (SMB) is commonly used for file sharing in Windows environments.

  • SMB Port: TCP 445
  • NetBIOS Port (Legacy): TCP 139 (often used with SMB for compatibility)

Using Nmap for SMB Enumeration:

  • Scan for Open SMB Ports:
    nmap -v -p 139,445 -oG smb_scan.txt 192.168.159.0/24
    grep "open" smb_scan.txt
    
  • OS Discovery via SMB:
    nmap -v -p 139,445 --script smb-os-discovery 192.168.159.152
    
  • List Available SMB NSE Scripts:
    ls -1 /usr/share/nmap/scripts/smb*
    

Other SMB Enumeration Tools:

  • NBTScan
  • Enum4Linux
  • SMBClient

Windows SMB Commands:

  • List shares on a remote machine:
    net view \\dc01 /all
    

SMTP Enumeration

Simple Mail Transfer Protocol (SMTP) runs on TCP port 25. Enumeration can reveal valid usernames.

Techniques:

  • VRFY: Asks the server to verify an email address.
  • EXPN: Asks the server for the membership of a mailing list (often disabled).

Manual Enumeration with nc:

nc -nv 192.168.50.8 25
# Connected... Server sends banner (e.g., 220 mail ESMTP Postfix)
VRFY root
# Server responds (e.g., 252 2.0.0 root)
VRFY nonexistantuser
# Server responds (e.g., 550 5.1.1 <nonexistantuser>: Recipient address rejected...)
QUIT

Using a Script (Example: vrfy.py)

A simple Python script can automate VRFY checks against a list of usernames. (See original note for script code).

Using Telnet:

Telnet can also be used for interactive SMTP sessions.

telnet 192.168.178.8 25
# Connected... Server sends banner
VRFY root
# Server responds
QUIT

Windows SMTP Checks:

  • Test Connection:
    Test-NetConnection -Port 25 192.168.50.8
    
  • Install and Use Telnet Client:
    # Enable Telnet Client feature if not already installed
    dism /online /Enable-Feature /FeatureName:TelnetClient
    # Connect using Telnet
    telnet 192.168.50.8 25
    

SNMP Enumeration

Simple Network Management Protocol (SNMP) typically uses UDP port 161. It can expose a wealth of system information if misconfigured.

MIB (Management Information Base):

A hierarchical database containing manageable objects on a device. OIDs (Object Identifiers) point to specific pieces of information.

Common OIDs for Enumeration:

OID Information
1.3.6.1.2.1.25.1.6.0 System Processes
1.3.6.1.2.1.25.4.2.1.2 Running Programs
1.3.6.1.2.1.25.4.2.1.4 Process Path
1.3.6.1.2.1.25.2.3.1.4 Storage Units
1.3.6.1.2.1.25.6.3.1.2 Installed Software Names
1.3.6.1.4.1.77.1.2.25 User Accounts
1.3.6.1.2.1.6.13.1.3 TCP Local Ports

Scanning for SNMP Hosts:

  • Nmap UDP Scan:
    sudo nmap -sU --open -p 161 192.168.50.0/24 -oG open_snmp.txt
    grep "open" open_snmp.txt
    

SNMP Enumeration Tools:

  • Onesixtyone: Fast scanner to check for common community strings (e.g., ‘public’, ‘private’).
  • SNMPWalk: Tool to query and walk the MIB tree of an SNMP-enabled device.

DNS 열거(Enumeration)

정찰(reconnaissance)을 제대로 하려면 다양한 DNS 레코드 유형을 알아 두는 게 중요합니다.

  • NS (Name Server): 도메인의 권한 있는(authoritative) DNS 서버를 가리킵니다.
  • A (Host): 호스트 이름을 IPv4 주소로 매핑합니다.
  • AAAA (IPv6 Host): 호스트 이름을 IPv6 주소로 매핑합니다.
  • MX (Mail Exchanger): 도메인의 메일을 처리하는 메일 서버를 지정합니다.
  • PTR (Pointer): 역방향 DNS 조회에서 IP 주소에 연결된 도메인 이름을 찾을 때 씁니다.
  • CNAME (Canonical Name): 다른 호스트 이름의 별칭을 만듭니다.
  • TXT (Text): 임의의 텍스트 데이터를 담을 수 있고, 주로 도메인 검증(예: SPF, DKIM)에 쓰입니다.

Unix 도구:

  • host: DNS 조회를 위한 간단한 유틸리티.
    host www.example.com
    host -t mx example.com
    host -t txt example.com
    
  • DNSRecon: DNS 열거를 위한 더 고급 Python 스크립트.
    # Standard enumeration
    dnsrecon -d example.com -t std
    # Brute-force subdomains using a wordlist
    dnsrecon -d example.com -D ~/list.txt -t brt
    
  • dnsenum: 또 다른 인기 있는 DNS 열거 스크립트.
    dnsenum example.com
    

Windows 도구:

  • nslookup: DNS를 질의하는 표준 Windows 명령줄 도구.
    nslookup mail.example.com
    # Query a specific record type against a specific DNS server
    nslookup -type=TXT info.example.com 192.168.1.1
    
  • net view: Windows 환경에서 (엄밀히 DNS는 아니지만) 정보를 드러내기도 한다.
    net view \\dc01 /all
    

Netcat(nc)를 이용한 포트 스캐닝

nc가 Nmap 같은 전용 포트 스캐너는 아니지만, 기본적인 포트 확인 정도는 충분히 해냅니다. 다만 보통 더 느리고 기능도 단출하죠.

옵션:

  • -n: 호스트 이름을 해석하지 않는다(더 빠름).
  • -v/-vv: 상세 출력.
  • -w <seconds>: 연결 타임아웃.
  • -z: Zero-I/O 모드(데이터를 보내지 않고 스캔).
  • -u: UDP 포트를 스캔.

예시:

  • 기본 TCP 포트 스캔:
    nc -nvv -w 3 -z 192.168.212.151 1-100
    
  • 기본 UDP 포트 스캔:
    nc -nv -u -z -w 1 192.168.50.149 120-123
    
  • 스레딩으로 더 빠르게 스캔(xargs 사용):
    # TCP Scan with 20 parallel connections
    seq 1000 10000 | xargs -P 20 -I {} nc -nvv -w 1 -z 192.168.50.151 {} 2>&1 | grep "open"
    # UDP Scan with 20 parallel connections
    seq 100 200 | xargs -P 20 -I {} nc -nvv -u -w 3 -z 192.168.159.151 {} 2>&1 | grep "open"
    

Nmap을 이용한 포트 스캐닝

Nmap은 포트 스캐닝과 네트워크 탐색의 사실상 업계 표준입니다.

Windows 대안:

  • Test-NetConnection: 특정 포트를 포함해 네트워크 연결성을 테스트하는 내장 PowerShell cmdlet.
    Test-NetConnection -Port 445 192.168.50.151
    
  • 포트 스캐닝용 PowerShell 루프:
    # Scan TCP ports 1-1024
    1..1024 | % { try { $tcpClient = New-Object Net.Sockets.TcpClient; $tcpClient.Connect("192.168.50.151", $_); Write-Output "TCP port $_ is open"; $tcpClient.Close() } catch {} } 2>$null
    
    # Scan the last octet for an open port (e.g., port 43)
    1..254 | ForEach-Object {
        $ip = "192.168.50.$_"
        try {
            $tcpClient = New-Object Net.Sockets.TcpClient
            $tcpClient.Connect($ip, 43)
            if ($tcpClient.Connected) { Write-Output "TCP port 43 is open on $ip"; $tcpClient.Close() }
        } catch {}
    }
    

SMB 열거

Server Message Block(SMB)은 Windows 환경에서 파일 공유에 흔히 쓰이는 프로토콜입니다.

  • SMB 포트: TCP 445
  • NetBIOS 포트(레거시): TCP 139 (호환성을 위해 SMB와 함께 자주 쓰임)

Nmap으로 SMB 열거:

  • 열린 SMB 포트 스캔:
    nmap -v -p 139,445 -oG smb_scan.txt 192.168.159.0/24
    grep "open" smb_scan.txt
    
  • SMB를 통한 OS 탐지:
    nmap -v -p 139,445 --script smb-os-discovery 192.168.159.152
    
  • 사용 가능한 SMB NSE 스크립트 목록:
    ls -1 /usr/share/nmap/scripts/smb*
    

기타 SMB 열거 도구:

  • NBTScan
  • Enum4Linux
  • SMBClient

Windows SMB 명령:

  • 원격 머신의 공유 목록 조회:
    net view \\dc01 /all
    

SMTP 열거

Simple Mail Transfer Protocol(SMTP)는 TCP 25번 포트에서 동작합니다. 이 열거를 잘 활용하면 유효한 사용자 이름을 캐낼 수 있죠.

기법:

  • VRFY: 서버에 이메일 주소를 검증해 달라고 요청합니다.
  • EXPN: 서버에 메일링 리스트 구성원을 물어봅니다(대개 비활성화돼 있죠).

nc를 이용한 수동 열거:

nc -nv 192.168.50.8 25
# Connected... Server sends banner (e.g., 220 mail ESMTP Postfix)
VRFY root
# Server responds (e.g., 252 2.0.0 root)
VRFY nonexistantuser
# Server responds (e.g., 550 5.1.1 <nonexistantuser>: Recipient address rejected...)
QUIT

스크립트 사용(예: vrfy.py)

간단한 Python 스크립트로 사용자 이름 목록에 대한 VRFY 검사를 자동화할 수 있습니다. (스크립트 코드는 원본 노트를 참고하세요.)

Telnet 사용:

Telnet으로도 인터랙티브 SMTP 세션을 열 수 있습니다.

telnet 192.168.178.8 25
# Connected... Server sends banner
VRFY root
# Server responds
QUIT

Windows SMTP 점검:

  • 연결 테스트:
    Test-NetConnection -Port 25 192.168.50.8
    
  • Telnet 클라이언트 설치 및 사용:
    # Enable Telnet Client feature if not already installed
    dism /online /Enable-Feature /FeatureName:TelnetClient
    # Connect using Telnet
    telnet 192.168.50.8 25
    

SNMP 열거

Simple Network Management Protocol(SNMP)은 보통 UDP 161번 포트를 씁니다. 그런데 설정이 허술하면 시스템 정보를 통째로 흘려 버릴 수 있어 눈여겨볼 만하죠.

MIB (Management Information Base):

장치의 관리 가능한 객체들을 담아 둔 계층형 데이터베이스입니다. 그 안에서 OID(Object Identifier)가 특정 정보 조각을 콕 집어 가리키죠.

열거에 유용한 대표 OID:

OID 정보
1.3.6.1.2.1.25.1.6.0 시스템 프로세스
1.3.6.1.2.1.25.4.2.1.2 실행 중인 프로그램
1.3.6.1.2.1.25.4.2.1.4 프로세스 경로
1.3.6.1.2.1.25.2.3.1.4 스토리지 단위
1.3.6.1.2.1.25.6.3.1.2 설치된 소프트웨어 이름
1.3.6.1.4.1.77.1.2.25 사용자 계정
1.3.6.1.2.1.6.13.1.3 TCP 로컬 포트

SNMP 호스트 스캔:

  • Nmap UDP 스캔:
    sudo nmap -sU --open -p 161 192.168.50.0/24 -oG open_snmp.txt
    grep "open" open_snmp.txt
    

SNMP 열거 도구:

  • Onesixtyone: 흔한 커뮤니티 스트링(예: ‘public’, ‘private’)을 확인하는 빠른 스캐너.
  • SNMPWalk: SNMP가 활성화된 장치의 MIB 트리를 질의하고 순회하는 도구.