File size: 3,073 Bytes
6325f92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""Command-line interface for the OSINT Expert Agent."""

from __future__ import annotations

import argparse

from .osint_agent import OSINTAgent


def interactive_mode(agent: OSINTAgent) -> None:
    print("OSINT Expert Agent — Interactive Mode")
    print("Commands: 'exit'/'quit' to end, 'reset' to clear history.\n")
    while True:
        try:
            user_input = input("You: ").strip()
        except (EOFError, KeyboardInterrupt):
            print("\nExiting.")
            break
        if not user_input:
            continue
        if user_input.lower() in ("exit", "quit"):
            print("Session ended.")
            break
        if user_input.lower() == "reset":
            agent.reset()
            print("[Conversation history cleared]\n")
            continue
        print("Agent: ", end="", flush=True)
        for chunk in agent.stream_chat(user_input):
            print(chunk, end="", flush=True)
        print("\n")


def main() -> None:
    parser = argparse.ArgumentParser(
        description="OSINT Expert Agent powered by Claude 3.5 Sonnet",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
Examples:
  python -m agent.cli                               # interactive mode
  python -m agent.cli --target example.com          # full analysis
  python -m agent.cli --target example.com --type passive
  python -m agent.cli --target 1.2.3.4 --type threat --context "seen in phishing"
  python -m agent.cli --iocs 1.2.3.4 bad.com abc123hash
  python -m agent.cli --explain "certificate transparency log mining"
        """,
    )
    parser.add_argument("--target", "-t", help="Target to analyze (domain, IP, username, etc.)")
    parser.add_argument(
        "--type",
        choices=["full", "passive", "threat", "footprint", "breach", "darkweb", "socmint"],
        default="full",
        help="Analysis type (default: full)",
    )
    parser.add_argument("--context", "-c", help="Additional context for the analysis")
    parser.add_argument("--iocs", nargs="+", metavar="IOC", help="IOCs for enrichment report")
    parser.add_argument("--explain", "-e", metavar="TECHNIQUE", help="Explain an OSINT technique")
    parser.add_argument("--model", default="claude-3-5-sonnet-20241022", help="Claude model to use")
    parser.add_argument("--no-stream", action="store_true", help="Disable streaming output")

    args = parser.parse_args()
    agent = OSINTAgent(model=args.model)

    if args.iocs:
        result = agent.generate_ioc_report(args.iocs)
        print(result)
    elif args.explain:
        result = agent.explain_technique(args.explain)
        print(result)
    elif args.target:
        prompt = OSINTAgent._build_analysis_prompt(args.target, args.type, args.context)
        if args.no_stream:
            result = agent.chat(prompt)
            print(result)
        else:
            for chunk in agent.stream_chat(prompt):
                print(chunk, end="", flush=True)
            print()
    else:
        interactive_mode(agent)


if __name__ == "__main__":
    main()