summarylogtreecommitdiffstats
path: root/openleecher.py
blob: f5d56f662715e61b86f97b1c8d33ce07732754e0 (plain)
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
import logging
import os, sys
import random
import sys
import time
import gui
from threading import Thread

from termcolor import cprint

from core import OpenLeecher
from kbhit import KBHit

# Core class
# Handles the core, can be threaded
# Args : None
class Core(Thread):
    def __init__(self):
        Thread.__init__(self, target=self.run)
        self.core = OpenLeecher()

    def run(self):
        self.core.run()

ol = Core()

# Show Help
# Display help in console
# Args : None
def show_help():
    cprint("OpenLeecher v" + ol.core.VERSION, 'blue', attrs=['bold'])
    cprint("Made by lwsk", 'blue')
    cprint("https://openleecher.tk/\n", 'blue')
    cprint("Command line arguments:", attrs=['bold'])
    cprint("\t-b 0 : set behavior")
    cprint("\t-g IPGenerator : set generator(s)")
    cprint("\t-s WEBScanner FTPScanner : set scanner(s)")
    cprint("\t-t 8 : set thread limit at 8")
    cprint("\t-h : display help")
    cprint("\nBehaviors", attrs=['bold'])
    cprint("\t0 : Random")
    cprint("\t1 : Intelligent")
    cprint("\t2 : Complete")
    cprint("\nAvailable generator(s):", attrs=['bold'])
    for g in ol.core.generator.g:
        cprint("\t" + g.__class__.__name__)
    cprint("\nAvailable scanner(s):", attrs=['bold'])
    for s in ol.core.scanner.s:
        cprint("\t" + s.__class__.__name__)

# Reset UI
# Clear console screen and re-draw UI
# Args : None
def reset_UI():
    os.system('cls' if os.name == 'nt' else 'clear')
    print(""".-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.
|                                                               |
|     OpenLeecher v"""+ol.core.VERSION+"""                                          |
|                                                               |
|     Generators :                                              |""")
    for g in ol.core.generator.g:
        if g.active is True:
            print("""
|            """+str(g.__class__.__name__).strip()+"""                                      |""")
    print("""
!                                                               !
:                                                               :
:     Scanners :                                                :""")
    for s in ol.core.scanner.s:
        if s.active is True:
            print("""
.            """+str(s.__class__.__name__).strip()+"""                                         .""")
    print("""
:                                                               :
:                                                               :
!                                                               !
|     Controls :                                                |
|         'o'        Raise maximum thread limit                 |
|         'l'        Lower maximum thread limit                 |
|         'p'        Toggle auto-open                           |
|         space      Pause/Resume generator                     |
|         'q' / esc  Quit                                       |
|                                                               |
`-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-'
    """)
    print("\n")


def run_core():
    running = True
    reset_UI()
    kb = KBHit()
    while running:
        if kb.kbhit():
            c = kb.getch()
            if len(c) > 0:
                if c == 'q' or ord(c) is 27: # esc
                    running = False
                elif c == 'o':
                    ol.core.maxthreads += 1
                elif c == 'l':
                    if ol.core.maxthreads > 0:
                        ol.core.maxthreads -= 1
                elif c == 'p':
                    ol.core.autoopen = not ol.core.autoopen
                elif ord(c) is 32 : # space
                    ol.core.paused = not ol.core.paused
                #else:
                    #sys.stdout.write('\r' + 'Keycode not registered ' + str(ord(c)) + '\n')

        pre = ""
        if ol.core.paused is True:
            pre += '[PAUSED] '
        if ol.core.autoopen is True:
            pre += '[AUTO-OPEN] '

        sys.stdout.write("\r" + pre + str(len(ol.core.threads)) + "/" + str(ol.core.maxthreads) + " threads running" + ('.' * random.randint(1, 3)) + "           ")

        # Notifications
        if len(ol.core.scanner.results) > 0:
            x = ol.core.scanner.results.pop(0)
            sys.stdout.write("\r" + "Found " + str(x.p) + " @ " + str(x.v) + '\n')

        time.sleep(0.04)

    sys.stdout.write("\r" + "Quitting OpenLeecher..." + "\n")
    logging.info("Quitting OpenLeecher...")
    sys.exit(0)


def start():
    for i in range(1, len(sys.argv)):
        a = sys.argv[i]
        if str(a) == '-h':
            show_help()
            run = False
            logging.info("Quitting OpenLeecher...")
            sys.exit(0)
        elif str(a) == '--gui':
            gui.launch()

        elif str(a) == '-t':
            try:
                ol.core.maxthreads = int(sys.argv[i + 1])
            except:
                run = False
                cprint("Error !", 'red', attrs=['bold']),
                print("Thread limit argument (-t) value is invalid")

        elif str(a) == '-b':
            try:
                ol.core.behavior = int(sys.argv[i + 1])
            except:
                run = False
                cprint("Error !", 'red', attrs=['bold']),
                print("Thread limit argument (-t) value is invalid")

        elif str(a) == '-g':
            j = 1
            try:
                while str(sys.argv[i + j]).startswith('-') is False:
                    if ol.core.generator.activate(str(sys.argv[i + j])) is False:
                        cprint("Error !", 'red', attrs=['bold']),
                        print("Generator " + str(sys.argv[i + j]) + " cannot be loaded.")
                        logging.error("Error : Generator " + str(sys.argv[i + j]) + " cannot be loaded.")
                        break
                    j += 1
            except:
                pass

        elif str(a) == '-s':
            j = 1
            try:
                while str(sys.argv[i + j]).startswith('-') is False:
                    if ol.core.scanner.activate(str(sys.argv[i + j])) is False:
                        cprint("Error !", 'red', attrs=['bold']),
                        print("Scanner " + str(sys.argv[i + j]) + " cannot be loaded.")
                        logging.error("Error : Scanner " + str(sys.argv[i + j]) + " cannot be loaded.")
                        break
                    j += 1
            except:
                pass

    if ol.core.can_run() is True:
        ol.start()
        run_core()
    else:
        cprint("Error !", 'red', attrs=['bold'])
        print("There must be at least one generator and one scanner active.")
        logging.error("Error : There must be at least one generator and one scanner active.")
        logging.warning("Cannot start session.")
        logging.info("Quitting OpenLeecher...")
        sys.exit(0)

if __name__ == '__main__':
    start()