-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosintchan.py
More file actions
403 lines (340 loc) · 14.9 KB
/
osintchan.py
File metadata and controls
403 lines (340 loc) · 14.9 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/usr/bin/env python3
"""
OSINTChan - 4chan/8kun OSINT Collection Tool
Searches and archives threads from imageboards for investigation purposes
"""
import requests
import argparse
import json
import sys
import time
from datetime import datetime
from typing import Dict, List, Optional
class OSINTChan:
def __init__(self):
# 4chan API endpoints - No API key required
self.fourchan_api = "https://a.4cdn.org"
self.fourchan_boards = "https://a.4cdn.org/boards.json"
self.fourchan_images = "https://i.4cdn.org"
# 8kun API endpoints - No API key required
self.eightkun_api = "https://8kun.top"
self.results = {}
def get_boards(self, site: str = "4chan") -> Dict:
"""Get list of available boards"""
print(f"[*] Fetching boards from {site}...")
try:
if site == "4chan":
response = requests.get(self.fourchan_boards, timeout=10)
if response.status_code == 200:
data = response.json()
boards = []
for board in data.get("boards", []):
boards.append({
"board": board.get("board"),
"title": board.get("title"),
"meta_description": board.get("meta_description"),
"is_archived": board.get("is_archived", 0)
})
return {
"site": site,
"boards_found": len(boards),
"boards": boards
}
else:
return {"error": f"{site} API error: {response.status_code}"}
else:
return {"error": f"Site {site} not yet implemented"}
except Exception as e:
return {"error": str(e)}
def get_catalog(self, board: str, site: str = "4chan") -> Dict:
"""Get catalog of threads for a board"""
print(f"[*] Fetching catalog for /{board}/ on {site}...")
try:
if site == "4chan":
url = f"{self.fourchan_api}/{board}/catalog.json"
response = requests.get(url, timeout=10)
if response.status_code == 200:
data = response.json()
threads = []
for page in data:
for thread in page.get("threads", []):
threads.append({
"no": thread.get("no"),
"subject": thread.get("sub", "No subject"),
"comment": thread.get("com", "")[:200], # First 200 chars
"name": thread.get("name", "Anonymous"),
"time": thread.get("time"),
"replies": thread.get("replies", 0),
"images": thread.get("images", 0),
"sticky": thread.get("sticky", 0),
"closed": thread.get("closed", 0)
})
return {
"site": site,
"board": board,
"threads_found": len(threads),
"threads": threads
}
else:
return {"error": f"{site} API error: {response.status_code}"}
else:
return {"error": f"Site {site} not yet implemented"}
except Exception as e:
return {"error": str(e)}
def get_thread(self, board: str, thread_no: int, site: str = "4chan") -> Dict:
"""Get full thread with all posts"""
print(f"[*] Fetching thread /{board}/{thread_no} from {site}...")
try:
if site == "4chan":
url = f"{self.fourchan_api}/{board}/thread/{thread_no}.json"
response = requests.get(url, timeout=10)
if response.status_code == 200:
data = response.json()
posts = []
for post in data.get("posts", []):
post_data = {
"no": post.get("no"),
"time": post.get("time"),
"name": post.get("name", "Anonymous"),
"subject": post.get("sub", ""),
"comment": post.get("com", ""),
"trip": post.get("trip", ""),
"id": post.get("id", ""),
"capcode": post.get("capcode", "")
}
# Add image info if present
if post.get("filename"):
post_data["image"] = {
"filename": post.get("filename"),
"ext": post.get("ext"),
"tim": post.get("tim"),
"md5": post.get("md5"),
"size": post.get("fsize"),
"image_url": f"{self.fourchan_images}/{board}/{post.get('tim')}{post.get('ext')}"
}
posts.append(post_data)
return {
"site": site,
"board": board,
"thread_no": thread_no,
"posts_found": len(posts),
"posts": posts,
"thread_url": f"https://boards.4chan.org/{board}/thread/{thread_no}"
}
elif response.status_code == 404:
return {
"error": "Thread not found (404) - may have been deleted or archived"
}
else:
return {"error": f"{site} API error: {response.status_code}"}
else:
return {"error": f"Site {site} not yet implemented"}
except Exception as e:
return {"error": str(e)}
def search_catalog(self, board: str, keyword: str, site: str = "4chan") -> Dict:
"""Search catalog for threads containing keyword"""
print(f"[*] Searching /{board}/ for '{keyword}' on {site}...")
catalog = self.get_catalog(board, site)
if "error" in catalog:
return catalog
keyword_lower = keyword.lower()
matching_threads = []
for thread in catalog.get("threads", []):
subject = thread.get("subject", "").lower()
comment = thread.get("comment", "").lower()
if keyword_lower in subject or keyword_lower in comment:
matching_threads.append(thread)
return {
"site": site,
"board": board,
"keyword": keyword,
"matches_found": len(matching_threads),
"threads": matching_threads
}
def get_archived_threads(self, board: str, site: str = "4chan") -> Dict:
"""Get list of archived threads"""
print(f"[*] Fetching archived threads for /{board}/ on {site}...")
try:
if site == "4chan":
url = f"{self.fourchan_api}/{board}/archive.json"
response = requests.get(url, timeout=10)
if response.status_code == 200:
archived = response.json()
return {
"site": site,
"board": board,
"archived_threads": len(archived),
"thread_ids": archived[:100] # First 100
}
else:
return {"error": f"{site} API error: {response.status_code}"}
else:
return {"error": f"Site {site} not yet implemented"}
except Exception as e:
return {"error": str(e)}
def run_investigation(self, board: str, operation: str, **kwargs) -> Dict:
"""Run investigation operation"""
print(f"\n[+] Starting OSINTChan investigation")
print(f"[+] Board: /{board}/")
print(f"[+] Operation: {operation}")
print(f"[+] Timestamp: {datetime.now().isoformat()}\n")
site = kwargs.get("site", "4chan")
results = {
"board": board,
"operation": operation,
"site": site,
"timestamp": datetime.now().isoformat()
}
if operation == "catalog":
results["data"] = self.get_catalog(board, site)
elif operation == "thread":
thread_no = kwargs.get("thread_no")
if not thread_no:
results["error"] = "Thread number required for thread operation"
else:
results["data"] = self.get_thread(board, thread_no, site)
elif operation == "search":
keyword = kwargs.get("keyword")
if not keyword:
results["error"] = "Keyword required for search operation"
else:
results["data"] = self.search_catalog(board, keyword, site)
elif operation == "archive":
results["data"] = self.get_archived_threads(board, site)
elif operation == "boards":
results["data"] = self.get_boards(site)
else:
results["error"] = f"Unknown operation: {operation}"
return results
def save_results(self, results: Dict, output_file: str):
"""Save results to JSON file"""
with open(output_file, 'w') as f:
json.dump(results, f, indent=2)
print(f"\n[+] Results saved to: {output_file}")
def print_results(self, results: Dict):
"""Print results to console"""
print("\n" + "="*60)
print("OSINTCHAN INVESTIGATION RESULTS")
print("="*60)
print(f"Board: /{results.get('board', 'N/A')}/")
print(f"Operation: {results.get('operation')}")
print(f"Site: {results.get('site')}")
print(f"Timestamp: {results.get('timestamp')}")
print("="*60)
data = results.get("data", {})
if "error" in results:
print(f"\nError: {results['error']}")
elif "error" in data:
print(f"\nError: {data['error']}")
else:
operation = results.get("operation")
if operation == "catalog":
threads = data.get("threads", [])
print(f"\nThreads found: {len(threads)}")
print("\nRecent threads:")
for thread in threads[:10]:
print(f"\n Thread #{thread['no']}")
print(f" Subject: {thread['subject']}")
print(f" Replies: {thread['replies']} | Images: {thread['images']}")
if thread.get('sticky'):
print(f" [STICKY]")
elif operation == "thread":
posts = data.get("posts", [])
print(f"\nPosts found: {len(posts)}")
print(f"Thread URL: {data.get('thread_url')}")
print("\nFirst post:")
if posts:
op = posts[0]
print(f" #{op['no']} - {op['name']} - {op['time']}")
print(f" Subject: {op['subject']}")
print(f" Comment: {op['comment'][:200]}")
elif operation == "search":
matches = data.get("matches_found", 0)
print(f"\nMatches found: {matches}")
threads = data.get("threads", [])
for thread in threads[:10]:
print(f"\n Thread #{thread['no']}")
print(f" Subject: {thread['subject']}")
print(f" Comment: {thread['comment'][:150]}")
elif operation == "archive":
count = data.get("archived_threads", 0)
print(f"\nArchived threads: {count}")
elif operation == "boards":
boards = data.get("boards", [])
print(f"\nBoards found: {len(boards)}")
print("\nAvailable boards:")
for board in boards[:20]:
print(f" /{board['board']}/ - {board['title']}")
print("\n" + "="*60)
def main():
parser = argparse.ArgumentParser(
description="OSINTChan - 4chan/8kun OSINT Collection Tool",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
List all boards:
python osintchan.py -o boards
Get catalog for /pol/:
python osintchan.py pol -o catalog
Get specific thread:
python osintchan.py pol -o thread -t 123456789
Search for keyword:
python osintchan.py pol -o search -k "election"
Get archived threads:
python osintchan.py pol -o archive
"""
)
parser.add_argument(
"board",
nargs="?",
help="Board name (e.g., pol, b, int)"
)
parser.add_argument(
"-o", "--operation",
choices=["catalog", "thread", "search", "archive", "boards"],
required=True,
help="Operation to perform"
)
parser.add_argument(
"-t", "--thread",
type=int,
help="Thread number (for thread operation)"
)
parser.add_argument(
"-k", "--keyword",
help="Keyword to search for (for search operation)"
)
parser.add_argument(
"-s", "--site",
choices=["4chan", "8kun"],
default="4chan",
help="Imageboard site (default: 4chan)"
)
parser.add_argument(
"-f", "--output",
help="Output file for JSON results"
)
args = parser.parse_args()
# Validate arguments
if args.operation != "boards" and not args.board:
parser.error("board is required for this operation")
if args.operation == "thread" and not args.thread:
parser.error("-t/--thread is required for thread operation")
if args.operation == "search" and not args.keyword:
parser.error("-k/--keyword is required for search operation")
# Run investigation
osintchan = OSINTChan()
results = osintchan.run_investigation(
board=args.board or "",
operation=args.operation,
site=args.site,
thread_no=args.thread,
keyword=args.keyword
)
# Print results
osintchan.print_results(results)
# Save if output file specified
if args.output:
osintchan.save_results(results, args.output)
if __name__ == "__main__":
main()