| Line 7: |
Line 7: |
| | | | |
| | == Python script to scan ports from attackers == | | == Python script to scan ports from attackers == |
| − | <source lang=python>import optparse | + | <source lang=python>import os |
| | + | import optparse |
| | from socket import * | | from socket import * |
| | + | |
| | + | |
| | + | PATH="/opt/counter_attack_ssh" |
| | + | |
| | def main(): | | def main(): |
| | parser = optparse.OptionParser('usage %prog -H <target host> -p <target port>') | | parser = optparse.OptionParser('usage %prog -H <target host> -p <target port>') |
| | parser.add_option('-H', dest='tgtHost', type='string', help='specify target host') | | parser.add_option('-H', dest='tgtHost', type='string', help='specify target host') |
| | (options, args) = parser.parse_args() | | (options, args) = parser.parse_args() |
| − |
| |
| | tgtHost = options.tgtHost | | tgtHost = options.tgtHost |
| − |
| + | tgtPorts = [20, 21, 22, 23, 25, 53, 67, 68, 69, 80, 110, 123, 137, 138, 139, 143, 161, 162, 179, 389, 443, 445, 636, 989, 990] |
| − | tgtPorts = [20,21,22,23,25,53,67,68,69,80,110,123,137,138,139,143,161,162,179,389,443,636,989,990] | + | with open(os.path.join(PATH, 'already_scanned.txt'), 'ra') as already_scanned: |
| − |
| |
| − | with open('already_scanned.txt', 'ra') as already_scanned: | |
| − |
| |
| | already_scanned_list = already_scanned.readlines() | | already_scanned_list = already_scanned.readlines() |
| − |
| |
| | already_scanned_list = [x.strip() for x in already_scanned_list] | | already_scanned_list = [x.strip() for x in already_scanned_list] |
| − |
| |
| | if (tgtHost == None): | | if (tgtHost == None): |
| | print parser.usage | | print parser.usage |
| Line 30: |
Line 29: |
| | print "IP already scanned" | | print "IP already scanned" |
| | else: | | else: |
| − | already_scanned = open('already_scanned.txt', 'a') | + | already_scanned = open(os.path.join(PATH, 'already_scanned.txt'), 'a') |
| | already_scanned.write(str(tgtHost) + "\n" ) | | already_scanned.write(str(tgtHost) + "\n" ) |
| | already_scanned.close() | | already_scanned.close() |
| Line 41: |
Line 40: |
| | connSkt.connect((tgtHost, tgtPort)) | | connSkt.connect((tgtHost, tgtPort)) |
| | print '[+] %d/tcp open' % tgtPort | | print '[+] %d/tcp open' % tgtPort |
| − | f = open('open_ports.txt', 'a') | + | f = open(os.path.join(PATH, 'open_ports.txt'), 'a') |
| | f.write("HOST: " + str(tgtHost) + " PORT ---> " + str(tgtPort) + "\n") | | f.write("HOST: " + str(tgtHost) + " PORT ---> " + str(tgtPort) + "\n") |
| | f.close() | | f.close() |
| Line 65: |
Line 64: |
| | connScan(tgtHost, int(tgtPort)) | | connScan(tgtHost, int(tgtPort)) |
| | if __name__ == '__main__': | | if __name__ == '__main__': |
| − | main()</source> | + | main() |
| | + | </source> |
| | | | |
| | == counter_attack.sh == | | == counter_attack.sh == |