strings 명령어의 고급 사용법 및 실용적인 응용
이 마지막 단계에서는 strings 명령어의 몇 가지 고급 사용 패턴과 실용적인 응용 프로그램을 살펴보겠습니다. 이러한 기술은 시스템 관리, 소프트웨어 개발 및 디지털 포렌식에 특히 유용할 수 있습니다.
랩 디렉토리에 있는지 확인합니다.
cd ~/project/strings_lab
다른 명령어와 strings 결합
strings 명령어의 진정한 힘은 다른 Linux 명령어와 결합할 때 나타납니다. 몇 가지 유용한 조합을 살펴보겠습니다.
잠재적으로 하드코딩된 자격 증명 찾기
보안 감사자는 종종 strings를 사용하여 바이너리 파일에서 하드코딩된 자격 증명을 찾습니다.
## Create a sample program with "credentials"
cat > credentials_example.c << EOF
#include <stdio.h>
int main() {
char* username = "admin";
char* password = "supersecret123";
printf("Connecting with credentials...\n");
return 0;
}
EOF
## Compile the program
gcc credentials_example.c -o credentials_example
이제 잠재적인 비밀번호를 검색해 보겠습니다.
strings credentials_example | grep -i 'password\|secret\|admin\|user\|login'
다음과 같은 출력이 나올 수 있습니다.
admin
supersecret123
password
이는 보안 감사자가 애플리케이션에서 잠재적으로 하드코딩된 자격 증명을 식별하는 방법을 보여줍니다.
파일 유형 분석
strings 명령어는 확장자가 없거나 오해의 소지가 있는 경우 파일 유형을 식별하는 데 도움이 될 수 있습니다.
## Create a PNG file without the correct extension
cp /usr/share/icons/Adwaita/16x16/places/folder.png mystery_file
이제 strings를 사용하여 파일 유형에 대한 단서를 찾아보겠습니다.
strings mystery_file | grep -i 'png\|jpeg\|gif\|image'
다음과 같은 출력을 볼 수 있습니다.
PNG
IHDR
pHYs
iDOT
PNG 관련 문자열이 있다는 것은 올바른 확장자가 없더라도 이 파일이 PNG 이미지일 수 있음을 시사합니다.
파일 오프셋과 함께 strings 사용
-t 옵션을 사용하면 파일 내 각 문자열의 오프셋을 볼 수 있으며, 이는 보다 자세한 분석에 유용할 수 있습니다.
## Create a sample binary file
cat > offset_example.bin << EOF
This is at the beginning of the file.
EOF
## Add some binary data
dd if=/dev/urandom bs=100 count=1 >> offset_example.bin 2> /dev/null
## Add another string
echo "This is in the middle of the file." >> offset_example.bin
## Add more binary data
dd if=/dev/urandom bs=100 count=1 >> offset_example.bin 2> /dev/null
## Add a final string
echo "This is at the end of the file." >> offset_example.bin
이제 -t 옵션과 함께 strings를 사용하여 오프셋을 확인해 보겠습니다.
strings -t d offset_example.bin
-t d 옵션은 10 진수 오프셋을 표시합니다. 출력 결과는 다음과 같을 수 있습니다.
0 This is at the beginning of the file.
137 This is in the middle of the file.
273 This is at the end of the file.
이 정보는 바이너리 패칭 또는 자세한 파일 분석과 같은 작업에 필수적인 바이너리 파일 내 문자열의 정확한 위치를 찾는 데 유용할 수 있습니다.
사례 연구: 네트워크 트래픽 분석
네트워크 패킷에는 종종 바이너리 데이터와 읽을 수 있는 텍스트가 모두 포함되어 있습니다. 캡처된 네트워크 패킷을 시뮬레이션하고 분석해 보겠습니다.
## Create a simulated network packet with HTTP data
cat > http_packet.bin << EOF
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html,application/xhtml+xml
EOF
## Add some binary header and footer to simulate packet framing
dd if=/dev/urandom bs=20 count=1 > packet_header.bin 2> /dev/null
dd if=/dev/urandom bs=20 count=1 > packet_footer.bin 2> /dev/null
## Combine them into a complete "packet"
cat packet_header.bin http_packet.bin packet_footer.bin > captured_packet.bin
이제 strings를 사용하여 이 "캡처된 패킷"을 분석해 보겠습니다.
strings captured_packet.bin
출력 결과에는 HTTP 요청이 포함되어야 합니다.
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html,application/xhtml+xml
이는 네트워크 분석가가 바이너리 프로토콜 데이터와 혼합된 경우에도 캡처된 네트워크 트래픽에서 유용한 정보를 빠르게 추출할 수 있는 방법을 보여줍니다.
고급 사용법 요약
이 단계에서 배운 기술은 고급 응용 프로그램에 대한 strings 명령어의 다재다능함을 보여줍니다.
- 특정 패턴을 검색하기 위해
strings를 grep과 결합
- 파일 유형을 식별하기 위해
strings 사용
- 정확한 바이너리 분석을 위한 파일 오프셋 작업
- 네트워크 패킷과 같은 혼합 바이너리 콘텐츠에서 읽을 수 있는 데이터 추출
이러한 기술은 특수 도구 없이 바이너리 데이터를 분석해야 하는 시스템 관리자, 보안 전문가 및 소프트웨어 개발자에게 유용합니다.