Shodan
Shodan: The Search Engine for Everything on the Internet
Introduction to Shodan
Shodan is often called the “search engine for hackers,” but a more accurate description is a search engine for internet-connected devices. Unlike Google, which indexes web content, Shodan indexes service banners, which are metadata that servers and devices send back in response to a connection request. This information can include details about the server software, device type, geographic location, and more. For cybersecurity professionals, including penetration testers and red teamers, Shodan is an indispensable tool for reconnaissance, vulnerability assessment, and threat intelligence.
This post will delve into how to effectively use Shodan, from basic search queries to advanced techniques using its command-line interface (CLI) and API.
How Shodan Works: Banner Grabbing
Shodan operates by continuously scanning the entire IPv4 address space on the internet. It sends connection requests to various ports on each IP address. When a device responds, Shodan captures the “banner,” which is the initial text-based response from the service running on that port.
For example, connecting to a web server on port 80 might return a banner revealing the server software (e.g., Apache, Nginx) and its version. Similarly, connecting to an FTP server on port 21 might reveal the FTP server software. Shodan collects, indexes, and makes this vast repository of banner information searchable.
Basic Search Filters
The true power of Shodan lies in its search filters. These allow you to narrow down billions of results to find exactly what you’re looking for. Here are some of the most fundamental filters:
country: Filters results by a two-letter country code.- Example:
country:US(United States)
- Example:
city: Filters results by city name.- Example:
city:"San Francisco"
- Example:
port: Filters for specific open ports.- Example:
port:3389(RDP)
- Example:
org: Filters by the organization name (ISP or company).- Example:
org:"Google LLC"
- Example:
hostname: Filters by text found in the hostname.- Example:
hostname:.gov
- Example:
os: Searches for a specific operating system.- Example:
os:"Windows Server 2016"
- Example:
product: Searches for a specific software or product name.- Example:
product:"Apache httpd"
- Example:
net: Filters by an IP range or CIDR notation.- Example:
net:8.8.8.0/24
- Example:
You can combine these filters to create highly specific queries. For instance, to find all Apache servers in Germany running on port 80, you would use:
1
product:"Apache httpd" country:DE port:80
Practical Use Cases for Security Professionals
Let’s explore some practical examples of how security professionals can leverage Shodan for reconnaissance.
1. Finding Exposed Databases
Unsecured databases are a common and critical vulnerability. You can use Shodan to find them.
- MongoDB (Port 27017):
1
port:27017 "mongodb server information"
- Elasticsearch (Port 9200):
1
port:9200 "You Know, for Search"
2. Identifying Vulnerable Systems
Shodan integrates with vulnerability databases, allowing you to search for systems affected by specific CVEs.
- Searching by CVE ID:
1
vuln:CVE-2021-44228
This query would find systems potentially vulnerable to the Log4Shell vulnerability.
3. Locating Industrial Control Systems (ICS)
Exposed ICS devices can have severe real-world consequences. Shodan is notoriously effective at finding these systems.
- Using the
icstag: Shodan has a dedicated tag for ICS-related devices.1
tag:ics
- Searching by protocol: You can also search for common ICS protocols.
1
port:502 modbus
4. Discovering Remote Desktop (RDP) and VNC Servers
Exposed remote access services are a common entry point for attackers.
- RDP (Port 3389):
1
port:3389
- VNC (Port 5900):
1
"authentication disabled" port:5900
This query specifically looks for VNC servers that have authentication disabled, a critical security risk.
Using the Shodan CLI
For automation and integration into scripts, the Shodan Command-Line Interface (CLI) is extremely powerful.
First, install it using pip:
1
pip install shodan
Then, initialize it with your API key (found on your Shodan account page):
1
shodan init YOUR_API_KEY
Now you can perform searches directly from your terminal:
1
2
3
4
5
6
7
8
# Perform a search
shodan search "Microsoft-IIS/10.0" country:US
# Get information about a specific host
shodan host 8.8.8.8
# Download search results
shodan download --limit 1000 my_results 'apache country:DE'
Automating with the Shodan API
The Shodan API allows you to programmatically access its data, making it a valuable asset for custom security tools. Here is a simple Python script to perform a search and print the IP addresses of the results.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import shodan
import os
# Get the API key from an environment variable for security
SHODAN_API_KEY = os.environ.get('SHODAN_API_KEY')
if not SHODAN_API_KEY:
print("Error: Please set the SHODAN_API_KEY environment variable.")
exit()
try:
# Setup the api
api = shodan.Shodan(SHODAN_API_KEY)
# Perform the search
# Let's find Apache servers in Germany
query = 'apache country:DE'
results = api.search(query)
# Print the results
print(f"Results found: {results['total']}")
for result in results['matches']:
print(f"IP: {result['ip_str']}")
print(f"Port: {result['port']}")
print(f"Organization: {result.get('org', 'N/A')}")
print("-" * 20)
except shodan.APIError as e:
print(f"Error: {e}")
To run this script, first set your API key as an environment variable: export SHODAN_API_KEY='YOUR_API_KEY'
Then, execute the Python script.
Shodan: 인터넷에 연결된 모든 것을 위한 검색 엔진
Shodan 소개
Shodan은 종종 “해커를 위한 검색 엔진”이라고 불리지만, 더 정확한 설명은 인터넷에 연결된 디바이스를 위한 검색 엔진입니다. 웹 콘텐츠를 색인하는 Google과 달리, Shodan은 서버와 디바이스가 연결 요청에 응답하여 보내는 메타데이터인 서비스 배너를 색인합니다. 이 정보에는 서버 소프트웨어, 디바이스 유형, 지리적 위치 등에 대한 세부 정보가 포함될 수 있습니다. 침투 테스터 및 레드팀을 포함한 사이버 보안 전문가에게 Shodan은 정찰, 취약점 평가 및 위협 인텔리전스를 위한 필수적인 도구입니다.
이 글에서는 기본 검색 쿼리부터 명령줄 인터페이스(CLI) 및 API를 사용한 고급 기술에 이르기까지 Shodan을 효과적으로 사용하는 방법을 심층적으로 다룰 것입니다.
Shodan의 작동 방식: 배너 그래빙
Shodan은 인터넷의 전체 IPv4 주소 공간을 지속적으로 스캔하여 작동합니다. 각 IP 주소의 다양한 포트로 연결 요청을 보냅니다. 디바이스가 응답하면 Shodan은 해당 포트에서 실행 중인 서비스의 초기 텍스트 기반 응답인 “배너”를 캡처합니다.
예를 들어, 포트 80의 웹 서버에 연결하면 서버 소프트웨어(예: Apache, Nginx)와 그 버전을 드러내는 배너를 반환할 수 있습니다. 마찬가지로, 포트 21의 FTP 서버에 연결하면 FTP 서버 소프트웨어가 드러날 수 있습니다. Shodan은 이 방대한 배너 정보 저장소를 수집하고 색인하여 검색 가능하게 만듭니다.
기본 검색 필터
Shodan의 진정한 힘은 검색 필터에 있습니다. 이를 통해 수십억 개의 결과 중에서 원하는 것을 정확하게 찾아낼 수 있습니다. 다음은 가장 기본적인 필터 중 일부입니다.
country: 두 글자 국가 코드로 결과를 필터링합니다.- 예:
country:US(미국)
- 예:
city: 도시 이름으로 결과를 필터링합니다.- 예:
city:"San Francisco"
- 예:
port: 특정 열린 포트를 필터링합니다.- 예:
port:3389(RDP)
- 예:
org: 조직 이름(ISP 또는 회사)으로 필터링합니다.- 예:
org:"Google LLC"
- 예:
hostname: 호스트 이름에서 발견된 텍스트로 필터링합니다.- 예:
hostname:.gov
- 예:
os: 특정 운영 체제를 검색합니다.- 예:
os:"Windows Server 2016"
- 예:
product: 특정 소프트웨어 또는 제품 이름을 검색합니다.- 예:
product:"Apache httpd"
- 예:
net: IP 범위 또는 CIDR 표기법으로 필터링합니다.- 예:
net:8.8.8.0/24
- 예:
이러한 필터들을 결합하여 매우 구체적인 쿼리를 만들 수 있습니다. 예를 들어, 독일에서 포트 80에서 실행 중인 모든 Apache 서버를 찾으려면 다음을 사용합니다.
1
product:"Apache httpd" country:DE port:80
보안 전문가를 위한 실제 사용 사례
보안 전문가가 정찰을 위해 Shodan을 어떻게 활용할 수 있는지 몇 가지 실제 사례를 살펴보겠습니다.
1. 노출된 데이터베이스 찾기
보안이 취약한 데이터베이스는 흔하고 치명적인 취약점입니다. Shodan을 사용하여 이러한 데이터베이스를 찾을 수 있습니다.
- MongoDB (Port 27017):
1
port:27017 "mongodb server information"
- Elasticsearch (Port 9200):
1
port:9200 "You Know, for Search"
2. 취약한 시스템 식별
Shodan은 취약점 데이터베이스와 통합되어 특정 CVE의 영향을 받는 시스템을 검색할 수 있습니다.
- CVE ID로 검색:
1
vuln:CVE-2021-44228
이 쿼리는 Log4Shell 취약점에 잠재적으로 취약한 시스템을 찾습니다.
3. 산업 제어 시스템(ICS) 찾기
노출된 ICS 장치는 심각한 현실 세계의 결과를 초래할 수 있습니다. Shodan은 이러한 시스템을 찾는 데 매우 효과적입니다.
ics태그 사용: Shodan에는 ICS 관련 장치를 위한 전용 태그가 있습니다.1
tag:ics
- 프로토콜로 검색: 일반적인 ICS 프로토콜을 검색할 수도 있습니다.
1
port:502 modbus
4. 원격 데스크톱(RDP) 및 VNC 서버 발견
노출된 원격 액세스 서비스는 공격자의 일반적인 진입점입니다.
- RDP (Port 3389):
1
port:3389
- VNC (Port 5900):
1
"authentication disabled" port:5900
이 쿼리는 인증이 비활성화된 VNC 서버를 구체적으로 찾으며, 이는 중대한 보안 위험입니다.
Shodan CLI 사용하기
자동화 및 스크립트 통합을 위해 Shodan 명령줄 인터페이스(CLI)는 매우 강력합니다.
먼저, pip를 사용하여 설치합니다.
1
pip install shodan
그런 다음, API 키(Shodan 계정 페이지에서 찾을 수 있음)로 초기화합니다.
1
shodan init YOUR_API_KEY
이제 터미널에서 직접 검색을 수행할 수 있습니다.
1
2
3
4
5
6
7
8
# 검색 수행
shodan search "Microsoft-IIS/10.0" country:US
# 특정 호스트 정보 가져오기
shodan host 8.8.8.8
# 검색 결과 다운로드
shodan download --limit 1000 my_results 'apache country:DE'
Shodan API로 자동화하기
Shodan API를 사용하면 프로그래밍 방식으로 데이터에 액세스할 수 있어 맞춤형 보안 도구를 위한 귀중한 자산이 됩니다. 다음은 검색을 수행하고 결과의 IP 주소를 출력하는 간단한 Python 스크립트입니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import shodan
import os
# 보안을 위해 환경 변수에서 API 키 가져오기
SHODAN_API_KEY = os.environ.get('SHODAN_API_KEY')
if not SHODAN_API_KEY:
print("Error: Please set the SHODAN_API_KEY environment variable.")
exit()
try:
# API 설정
api = shodan.Shodan(SHODAN_API_KEY)
# 검색 수행
# 독일의 Apache 서버 찾기
query = 'apache country:DE'
results = api.search(query)
# 결과 출력
print(f"Results found: {results['total']}")
for result in results['matches']:
print(f"IP: {result['ip_str']}")
print(f"Port: {result['port']}")
print(f"Organization: {result.get('org', 'N/A')}")
print("-" * 20)
except shodan.APIError as e:
print(f"Error: {e}")
이 스크립트를 실행하려면 먼저 API 키를 환경 변수로 설정하십시오. export SHODAN_API_KEY='YOUR_API_KEY'
그런 다음 Python 스크립트를 실행합니다.