Skip to content

Instantly share code, notes, and snippets.

@piotrmaslanka
Last active December 30, 2021 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotrmaslanka/40f502a09a9bc405369e373a90531fb4 to your computer and use it in GitHub Desktop.
Save piotrmaslanka/40f502a09a9bc405369e373a90531fb4 to your computer and use it in GitHub Desktop.
Script to read the screen of a suitably equipped FRISKO PLC. Requires a Windows to run.
# Python 2
import socket # System lacznosci sieciowej
import WConio # System obslugi konsoli tekstowej
import msvcrt # Obsluga klawiatury, ta w WConio wydaje sie nawalac
from array import array # Edycja stringow (stringi w Pythonie sa niemodyfikowalne)
from struct import pack # Niezbedne do skladania pakietow w calosc
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Korzystamy z zestawu protokolow Internetowych,
# gniazdo strumieniowe
host = raw_input("Give the address (demo version - type DEMO): ")
if host=='DEMO':
host='85.128.102.30'
port = raw_input('Give a port, default is 9001: ')
s.connect((host,int(port))) # Lacz sie z 'DEMO'
def linijka_z_kolorem(linijka, pozycja, tryb_edycji):
if pozycja<0:
print linijka
return None
elif pozycja>len(linijka)-1:
print linijka
return None
for i in xrange(0,len(linijka)):
WConio.textcolor((WConio.GREEN if tryb_edycji==0 else WConio.RED) if i==pozycja else WConio.WHITE)
if (i==pozycja) and (linijka[i]==' '): # Jesli podswietlona jest spacja to jej nie widac
linijka = array("c", linijka) # Wiec zastap spacje bardziej konstruktywnym znakiem
linijka[i] = '_'
linijka = linijka.tostring()
WConio.cputs(linijka[i])
WConio.textcolor(WConio.WHITE)
WConio.cputs('\n')
def analizuj(dane):
linia = []
linia.append(dane[00:16])
linia.append(dane[16:32])
linia.append(dane[32:48])
linia.append(dane[48:64])
sterownik = dane[70:]
innedane = map(lambda x: ord(x), dane[64:70]) # Konwertuj inne dane na postac dziesietnia
# Gdyby byly w ASCII, bylyby tylko robaczki
WConio.clrscr() # Czysc ten ekran!
WConio.textcolor(WConio.WHITE) # Kolorek
print "Hissing Hacker (tm) by Piotr M."
print "PLC screen dump"
print "----------------"
linijka_z_kolorem(linia[0],innedane[0],innedane[1])
linijka_z_kolorem(linia[1],innedane[0]-16,innedane[1])
linijka_z_kolorem(linia[2],innedane[0]-32, innedane[1])
linijka_z_kolorem(linia[3],innedane[0]-48, innedane[1])
print "----------------"
print "PLC name: "+sterownik
print "Other data: "+str(innedane)
print ("Choice mode" if innedane[1]==0 else "Data edit mode")
print ""
print "Keyboard key : PLC key"
print "= : +"
print "- : -"
print "o : OK"
print "e : ESC"
print ", : <"
print ". : >"
print "x : QUIT THE PROGRAM"
def kk(plus,minus,ok,esc,prawo,lewo,haslo,sock):
b = 0
if esc:
b = b+1
if ok:
b = b+16
if plus:
b = b+8
if minus:
b = b+2
if prawo:
b = b+4
if lewo:
b = b+32
sock.send(pack('>hb',haslo,b))
if host=='85.128.102.30':
haslo=0
else:
haslo = int(raw_input("Haslo: "))
while True:
if msvcrt.kbhit(): # User cos nacisnal?
z = msvcrt.getch() # Jesli tak to zobacz co
if z=='=':
kk(True,False,False,False,False,False,haslo,s)
elif z=='-':
kk(False,True,False,False,False,False,haslo,s)
elif z=='o':
kk(False,False,True,False,False,False,haslo,s)
elif z=='e':
kk(False,False,False,True,False,False,haslo,s)
elif z=='.':
kk(False,False,False,False,False,True,haslo,s)
elif z==',':
kk(False,False,False,False,True,False,haslo,s)
elif z=='x':
del s
exit()
else:
kk(False,False,False,False,False,False,haslo,s)
else:
kk(False,False,False,False,False,False,haslo,s)
try:
analizuj(s.recv(1024))
except IndexError:
print "Error in communications or invalid password"
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment