Skip to content

Commit 617a92c

Browse files
committed
working on splitting the libraries
1 parent 1f639ac commit 617a92c

9 files changed

Lines changed: 165 additions & 60 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.6
1+
0.0.7

app/ctfsolver.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: ctfsolver
3-
Version: 0.0.5
3+
Version: 0.0.7
44
Summary: An all in one library for solving CTF challenges
55
Home-page: https://github.com/nikolasfil/CTFSolverScript
66
Author: Nikolas Filippatos

app/ctfsolver.egg-info/SOURCES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ app/ctfsolver/src/ctfsolver.py
2525
app/ctfsolver/src/manager_connections.py
2626
app/ctfsolver/src/manager_crypto.py
2727
app/ctfsolver/src/manager_file.py
28+
app/ctfsolver/src/manager_files_pcap.py
2829
app/ctfsolver/template/__init__.py
2930
app/ctfsolver/template/__main__.py
3031
app/ctfsolver/template/solution_template.py

app/ctfsolver/src/manager_crypto.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ class ManagerCrypto:
66
def __init__(self, *args, **kwargs) -> None:
77
pass
88

9-
def xor(self, text, key):
9+
def initializing_all_ancestors(self, *args, **kwargs):
10+
"""
11+
Description:
12+
Initializes all the ancestors of the class
13+
14+
"""
15+
pass
16+
17+
def xor(self, text: str, key: str) -> str:
1018
"""
1119
Description:
1220
XOR the text with the key
@@ -37,34 +45,7 @@ def decode_base64(self, text):
3745
print(e)
3846
return None
3947

40-
def searching_text_in_packets(self, text, packets=None, display=False):
41-
"""
42-
Description:
43-
Search for a text in the packets that have been opened with scapy
44-
45-
Args:
46-
text (str): Text to search in the packets
47-
packets (list, optional): List of packets to search in. Defaults to None.
48-
display (bool, optional): Display the packet if the text is found. Defaults to False.
49-
50-
Returns:
51-
str: Text found in the packet if found
52-
"""
53-
54-
# Todo : Transfer into a different class that will be mainly for packet analysis
55-
if not packets:
56-
packets = self.packets
57-
58-
for i, packet in enumerate(packets):
59-
if packet.haslayer("Raw"):
60-
if text.encode() in packet["Raw"].load:
61-
if display:
62-
print(f"Found {text} in packet {i}")
63-
print(packet.show())
64-
print(packet.summary())
65-
return packet["Raw"].load.decode("utf-8")
66-
67-
def re_match_base64_string(self, text, strict=False):
48+
def re_match_base64_string(self, text: str, strict=False) -> list[str]:
6849
"""
6950
Description:
7051
Find the base64 string in the text
@@ -83,7 +64,7 @@ def re_match_base64_string(self, text, strict=False):
8364
base64_strings = re.findall(base64_pattern, text)
8465
return base64_strings
8566

86-
def re_match_flag(self, text, origin):
67+
def re_match_flag(self, text: str, origin: str) -> list[str]:
8768
"""
8869
Description:
8970
Find the flag in the text
@@ -98,7 +79,7 @@ def re_match_flag(self, text, origin):
9879
flag_pattern = rf"{origin}{{[A-Za-z0-9_]+}}"
9980
return re.findall(flag_pattern, text)
10081

101-
def re_match_partial_flag(self, text, origin):
82+
def re_match_partial_flag(self, text: str, origin: str) -> list[str]:
10283
"""
10384
Description:
10485
Find the flag in the text or partial flag

app/ctfsolver/src/manager_file.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from pathlib import Path
22
import inspect
3-
from scapy.all import rdpcap
43
import os
54
import ast
5+
from .manager_files_pcap import ManagerFilePcap
66

77

8-
class ManagerFile:
8+
class ManagerFile(ManagerFilePcap):
99
def __init__(self, *args, **kwargs):
1010
self.Path = Path
1111
self.file = kwargs.get("file")
@@ -17,6 +17,13 @@ def __init__(self, *args, **kwargs):
1717
self.setup_named_folders()
1818
self.get_challenge_file()
1919

20+
def initializing_all_ancestors(self, *args, **kwargs):
21+
"""
22+
Description:
23+
Initializes all the ancestors of the class
24+
"""
25+
ManagerFilePcap.__init__(self, *args, **kwargs)
26+
2027
def get_parent(self):
2128
"""
2229
Description:
@@ -159,18 +166,6 @@ def exec_on_files(self, folder, func, *args, **kwargs):
159166
if save:
160167
return output
161168

162-
def pcap_open(self, file=None):
163-
"""
164-
Description:
165-
Open the pcap file with scapy and saves it in self.packets
166-
"""
167-
# Todo : Transfer into a different class that will be mainly for packet analysis
168-
169-
if not file:
170-
file = self.challenge_file
171-
172-
self.packets = rdpcap(file.as_posix())
173-
174169
def search_files(
175170
self, directory, exclude_dirs, search_string, save=False, display=False
176171
):
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from pathlib import Path
2+
import inspect
3+
from scapy.all import rdpcap
4+
import os
5+
import ast
6+
7+
8+
class ManagerFilePcap:
9+
def __init__(self, *args, **kwargs):
10+
pass
11+
12+
def initializing_all_ancestors(self, *args, **kwargs):
13+
"""
14+
Description:
15+
Initializes all the ancestors of the class
16+
"""
17+
18+
def pcap_open(self, file=None, save=False):
19+
"""
20+
Description:
21+
Open the pcap file with scapy and saves it in self.packets
22+
23+
Args:
24+
file (Path, optional): File to open. Defaults to None.
25+
save (bool, optional): Save the output. Defaults to False.
26+
27+
"""
28+
29+
if file is None:
30+
file = self.challenge_file
31+
32+
self.packets = rdpcap(file.as_posix())
33+
34+
if save:
35+
return self.packets
36+
37+
def searching_text_in_packets(self, text, packets=None, display=False):
38+
"""
39+
Description:
40+
Search for a text in the packets that have been opened with scapy
41+
42+
Args:
43+
text (str): Text to search in the packets
44+
packets (list, optional): List of packets to search in. Defaults to None.
45+
display (bool, optional): Display the packet if the text is found. Defaults to False.
46+
47+
Returns:
48+
str: Text found in the packet if found
49+
"""
50+
51+
if packets is None:
52+
packets = self.packets
53+
54+
for i, packet in enumerate(packets):
55+
if packet.haslayer("Raw"):
56+
if text.encode() in packet["Raw"].load:
57+
if display:
58+
print(f"Found {text} in packet {i}")
59+
print(packet.show())
60+
print(packet.summary())
61+
return packet["Raw"].load.decode("utf-8")

build/lib/ctfsolver/src/manager_crypto.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ class ManagerCrypto:
66
def __init__(self, *args, **kwargs) -> None:
77
pass
88

9-
def xor(self, text, key):
9+
def initializing_all_ancestors(self, *args, **kwargs):
10+
"""
11+
Description:
12+
Initializes all the ancestors of the class
13+
14+
"""
15+
pass
16+
17+
def xor(self, text: str, key: str) -> str:
1018
"""
1119
Description:
1220
XOR the text with the key
@@ -51,6 +59,7 @@ def searching_text_in_packets(self, text, packets=None, display=False):
5159
str: Text found in the packet if found
5260
"""
5361

62+
# Todo : Transfer into a different class that will be mainly for packet analysis
5463
if not packets:
5564
packets = self.packets
5665

@@ -63,7 +72,7 @@ def searching_text_in_packets(self, text, packets=None, display=False):
6372
print(packet.summary())
6473
return packet["Raw"].load.decode("utf-8")
6574

66-
def re_match_base64_string(self, text, strict=False):
75+
def re_match_base64_string(self, text: str, strict=False) -> list[str]:
6776
"""
6877
Description:
6978
Find the base64 string in the text
@@ -82,7 +91,7 @@ def re_match_base64_string(self, text, strict=False):
8291
base64_strings = re.findall(base64_pattern, text)
8392
return base64_strings
8493

85-
def re_match_flag(self, text, origin):
94+
def re_match_flag(self, text: str, origin: str) -> list[str]:
8695
"""
8796
Description:
8897
Find the flag in the text
@@ -97,7 +106,7 @@ def re_match_flag(self, text, origin):
97106
flag_pattern = rf"{origin}{{[A-Za-z0-9_]+}}"
98107
return re.findall(flag_pattern, text)
99108

100-
def re_match_partial_flag(self, text, origin):
109+
def re_match_partial_flag(self, text: str, origin: str) -> list[str]:
101110
"""
102111
Description:
103112
Find the flag in the text or partial flag

build/lib/ctfsolver/src/manager_file.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from scapy.all import rdpcap
44
import os
55
import ast
6+
from .manager_files_pcap import ManagerFilePcap
67

78

8-
class ManagerFile:
9+
class ManagerFile(ManagerFilePcap):
910
def __init__(self, *args, **kwargs):
1011
self.Path = Path
1112
self.file = kwargs.get("file")
@@ -17,6 +18,13 @@ def __init__(self, *args, **kwargs):
1718
self.setup_named_folders()
1819
self.get_challenge_file()
1920

21+
def initializing_all_ancestors(self, *args, **kwargs):
22+
"""
23+
Description:
24+
Initializes all the ancestors of the class
25+
"""
26+
ManagerFilePcap.__init__(self, *args, **kwargs)
27+
2028
def get_parent(self):
2129
"""
2230
Description:
@@ -32,6 +40,10 @@ def get_parent(self):
3240
self.parent = self.parent.parent
3341

3442
def setup_named_folder_list(self):
43+
"""
44+
Description:
45+
Setup the main named folder list. If the user has provided a list, add the must folders to it
46+
"""
3547
if self.folders_name_list is None:
3648
self.folders_name_list = self.folders_names_must
3749
elif len(self.folders_name_list) > 1:
@@ -41,7 +53,7 @@ def setup_named_folder_list(self):
4153
def setup_named_folders(self):
4254
"""
4355
Description:
44-
Create folders for the challenge
56+
Create folders for the challenge. (data, files, payloads)
4557
"""
4658

4759
self.folder_payloads = None
@@ -53,7 +65,10 @@ def setup_named_folders(self):
5365
self.folder_payloads = Path(self.parent, "payloads")
5466

5567
def create_parent_folder(self):
56-
""" """
68+
"""
69+
Description:
70+
Create the parent folder of the file that called the class if they don't exist
71+
"""
5772

5873
self.folder_data = Path(self.parent, "data")
5974
self.folder_files = Path(self.parent, "files")
@@ -65,17 +80,14 @@ def create_parent_folder(self):
6580
self.folder_files,
6681
]
6782

68-
# add the folders that are in the named_list but are not in the folder_list
69-
# Make the folder_list public
70-
7183
for folder in folder_list:
7284
if not folder.exists():
7385
folder.mkdir()
7486

7587
def prepare_space(self, files=None, folder=None, test_text="picoCTF{test}"):
7688
"""
7789
Description:
78-
Prepare the space for the challenge by creating the folders if they don't exist
90+
Prepare the space for the challenge by creating the folders if they don't exist, create files from the file list provided
7991
"""
8092
files = files if files else []
8193
folder = folder if folder else self.folder_files
@@ -86,9 +98,13 @@ def prepare_space(self, files=None, folder=None, test_text="picoCTF{test}"):
8698
f.write(test_text)
8799

88100
def get_challenge_file(self):
89-
if self.file and self.folder_data:
101+
"""
102+
Description:
103+
Get the challenge file and assign it to the self.challenge_file for ease of access
104+
"""
105+
if self.file and self.folder_files:
90106
self.challenge_file = Path(self.folder_files, self.file)
91-
elif not self.folder_data:
107+
elif not self.folder_files:
92108
if self.debug:
93109
print("Data folder not found")
94110

@@ -156,6 +172,7 @@ def pcap_open(self, file=None):
156172
Description:
157173
Open the pcap file with scapy and saves it in self.packets
158174
"""
175+
# Todo : Transfer into a different class that will be mainly for packet analysis
159176

160177
if not file:
161178
file = self.challenge_file
@@ -204,6 +221,12 @@ def search_files(
204221
return output
205222

206223
def search_for_base64(self, file, *args, **kwargs):
224+
"""
225+
Depracated, checkout search_for_base64_file
226+
"""
227+
return self.search_for_base64_file(file, *args, **kwargs)
228+
229+
def search_for_base64_file(self, file, *args, **kwargs):
207230
"""
208231
Description:
209232
Search for base64 string in the file

0 commit comments

Comments
 (0)