Add recon network batch 1: stack banners and smart port profiles.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Parse technology stack from crawl headers, grab SSH/HTTP/WinRM banners, merge smart port bundles with FleetPorts, and suggest deploy-kit lane plus SSM for EC2 metadata targets.
This commit is contained in:
34
scripts/batch1_build_scan.py
Normal file
34
scripts/batch1_build_scan.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(r"G:/crypto miner")
|
||||
scan = subprocess.check_output(
|
||||
["git", "-C", str(ROOT), "show", "HEAD:server/internal/recon/scan.go"],
|
||||
text=True,
|
||||
)
|
||||
scan = scan.replace(
|
||||
"import (\n\t\"fmt\"\n\t\"net\"\n\t\"strings\"\n\t\"time\"\n)",
|
||||
"import (\n\t\"bufio\"\n\t\"fmt\"\n\t\"io\"\n\t\"net\"\n\t\"net/http\"\n\t\"regexp\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n)",
|
||||
)
|
||||
scan = scan.replace(
|
||||
"func Scan(req ScanRequest) (*ScanReport, error) {\n\thost, err := normalizeOwnedHost(req.Host)",
|
||||
"func Scan(req ScanRequest) (*ScanReport, error) {\n\treturn runOwnedTargetScan(req, \"\", nil)\n}\n\nfunc scanLegacy(req ScanRequest) (*ScanReport, error) {\n\thost, err := normalizeOwnedHost(req.Host)",
|
||||
)
|
||||
scan = scan.replace("ports := ScanPorts(host)", "ports := ScanPorts(host, nil)")
|
||||
scan = scan.replace(
|
||||
"report.Recommendations = BuildRecommendations(ports, report.Crawl)",
|
||||
"report.Recommendations = BuildRecommendations(ports, report.Crawl, nil, host, false)",
|
||||
)
|
||||
scan = scan.replace(
|
||||
"func BuildRecommendations(ports []PortResult, crawl *CrawlReport) []DeployRecommendation {",
|
||||
"func BuildRecommendations(ports []PortResult, crawl *CrawlReport, stack []StackEntry, host string, cloudMetaProfile bool) []DeployRecommendation {",
|
||||
)
|
||||
scan = scan.replace("case 80, 443, 8080, 8443:", "case 80, 443, 6262, 8080, 8443:")
|
||||
# extend BuildRecommendations tail
|
||||
scan = scan.replace(
|
||||
"\treturn dedupeRecommendations(recs)\n}",
|
||||
"\tif lane := SuggestDeployKitLane(stack); lane != \"\" {\n\t\trecs = append(recs, DeployRecommendation{Lane: lane, Reason: fmt.Sprintf(\"Technology stack suggests %s deploy-kit lane\", lane), Priority: 18})\n\t}\n\tif cloudMetaProfile && (TargetLooksEC2(host) || ProbeEC2Metadata()) {\n\t\trecs = append(recs, DeployRecommendation{Lane: \"ssm_document\", Template: \"ssm_document\", Reason: \"cloud_metadata profile - EC2/IMDS reachable; SSM document lane\", Priority: 40})\n\t}\n\treturn dedupeRecommendations(recs)\n}",
|
||||
)
|
||||
extra = Path(__file__).with_name("_batch1_scan_extra.go").read_text(encoding="utf-8")
|
||||
Path(__file__).with_name("_batch1_scan.go").write_text(scan + extra, encoding="utf-8")
|
||||
print("built scan", len(scan + extra))
|
||||
Reference in New Issue
Block a user