Sandfly API
Sandfly server는 기능 확장을 위한 REST API를 제공합니다.
Sandfly API의 전체 호출 목록은 다음에서 확인할 수 있습니다: https://api.sandflysecurity.com/
추가적인 개발 관련 정보는 문서의 Forensics Keyword List 섹션을 참고하세요.
예제 API 스크립트
참고용으로, API를 통해 인증을 수행하고 Sandfly 버전을 조회하는 bash 스크립트를 제공합니다:
# Sandfly Security LTD www.sandflysecurity.com
# Copyright (c) Sandfly Security LTD, All Rights Reserved.
# A reference script for the Sandfly API, change data where appropriate
cat << EOF
******************************************************************************
Sandfly API Reference Script Example
This script will attempt to authenticate, get version data, and output it.
DOC: https://api.sandflysecurity.com/#get-/version
******************************************************************************
EOF
# Set changeable variables
APIVERSION="v4" # Version of the API used by the Sandfly Server
APIPATH="version" # API command to call on the Sandfly Server
JQFILTER="." # Filter for jq in the output section
REQUESTMETHOD="GET" # HTTP request method for data calls
REQUESTDATA="" # Data for any POST calls, leave blank for GET
# Check for required commands
if ! command -v jq &> /dev/null
then
echo "the 'jq' command could not be found and is required to run this script."
exit 1
fi
if ! command -v curl &> /dev/null
then
echo "The 'curl' command could not be found and is required to run this script."
exit 1
fi
# Prompt for entering connection data
read -p "Hostname for Sandfly server: " HOSTNAME
if [[ "$HOSTNAME" == "" ]]; then
echo "Must supply a hostname."
exit 1
fi
read -s -p "Password for Sandfly admin user: " PASSWORD
if [[ "$PASSWORD" == "" ]]; then
echo "Must supply a password."
exit 1
fi
# Attempt to connect to the API and obtain the access token
echo ""
echo ""
echo "Attempting to connect to the Sandfly API at: $HOSTNAME"
echo ""
ACCESS_JSON=$(curl -s -k --request POST \
--header "Content-Type: application/json" \
--url https://"$HOSTNAME"/"$APIVERSION"/auth/login \
--data "{\"username\":\"admin\",\"password\":\"$PASSWORD\"}")
ACCESS_TOKEN=$(echo $ACCESS_JSON | jq -r ".access_token")
if [[ "$ACCESS_JSON" == "" ]]; then
echo "AUTH STATUS: Failed, did not receive data from the host. Check hostname and credentials and try again."
exit 1
elif [[ "$ACCESS_TOKEN" == "null" ]]; then
echo "AUTH STATUS: Failed, did not get access token for REST API. Check hostname and credentials and try again."
exit 1
else
echo "AUTH STATUS: Passed, access token obtained."
fi
# Attempt to get and output the data
OUTPUT_JSON=$(curl -s -k --request "$REQUESTMETHOD" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--url https://"$HOSTNAME"/"$APIVERSION"/"$APIPATH" \
--data "$REQUESTDATA")
OUTPUT_STATUS=$(echo $OUTPUT_JSON | jq -r ".status")
OUTPUT_DETAIL=$(echo $OUTPUT_JSON | jq -r ".detail")
if [[ "$OUTPUT_JSON" == "null" ]]; then
echo "CALL STATUS: Failed, no JSON response."
exit 1
elif [[ "$OUTPUT_STATUS" -gt 399 ]]; then
echo "CALL STATUS: Failed, CODE:$OUTPUT_STATUS - $OUTPUT_DETAIL"
exit 1
else
echo "CALL STATUS: Passed, the output is:"
echo "$OUTPUT_JSON" | jq "$JQFILTER"
fi
# Wrap up the example
echo ""
echo "Script Finished!"
참고: 예제 스크립트에 필요한 외부 명령이 예제 스크립트는 curl 및 jq 명령이 필요합니다. 둘 중 하나라도 없으면 스크립트가 이를 알려줍니다. 스크립트를 실행하려면 사용하는 운영체제에 맞게 누락된 명령을 설치하세요.
이 스크립트는 bash, curl, jq 명령을 실행할 수 있고 Sandfly server의 관리 웹 인터페이스에 접근할 수 있는 모든 호스트에서 사용할 수 있습니다.
API 예제 스크립트
Sandfly 배포본에는 인증, GET/POST 호출, API를 통한 스캔 수행 등 다양한 핵심 기능을 수행하는 스크립트가 포함되어 있습니다. 해당 스크립트는 다음 경로에 있습니다: sandfly-setup/api_examples/
패키지된 API 사양
sandfly-setup 패키지에는 다음 위치에 관련 OpenAPI 사양이 포함되어 있습니다: sandfly-setup/api_examples/sandfly-openapi.yaml
Updated 7 days ago
이 페이지가 도움이 되었나요?