-
Notifications
You must be signed in to change notification settings - Fork 6
/
openstego.py
142 lines (132 loc) · 5.3 KB
/
openstego.py
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
import os, pwd, sys, gi, re, time, fcntl, pty
from gi.repository import Gtk, GObject
from subprocess import Popen, PIPE
home = pwd.getpwuid(os.getuid()).pw_dir + '/SSAK/'
execdir = os.path.dirname(os.path.realpath(sys.argv[0]))
stegprog = 'java -jar ' + re.escape(execdir) + '/programs/noarch/openstego.jar '
class openstego:
def togglepass(self, widget, data=None):
value=''
value = ("OFF", "ON")[widget.get_active()]
if value == "OFF":
self.pass2.set_property("editable", False)
if value == "ON":
self.pass2.set_property("editable", True)
def togglepass2(self, widget, data=None):
value=''
value = ("OFF", "ON")[widget.get_active()]
if value == "OFF":
self.pass4.set_property("editable", False)
if value == "ON":
self.pass4.set_property("editable", True)
def ostegembed2(self, widget):
value = ("OFF", "ON")[self.checkbutton3.get_active()]
value2 = ("OFF", "ON")[self.checkbutton2.get_active()]
self.sfile = self.file.get_text()
self.spass = self.pass2.get_text()
self.alg = (self.algorithm.get_active())
if self.alg == 0:
self.algorithm2 = "RandomLSB"
elif self.alg == 1:
self.algorithm2 = "LSB"
self.fchooser2.connect("delete-event", lambda window, event: self.fchooser2.destroy() or True)
self.hidefile2 = str(self.fchooser2.get_filename())
head, tail = os.path.split(self.sfile)
outdir = home + tail + '/openstegembed'
self.outfile2 = outdir + '/' + tail + '.png'
if not os.path.isdir(outdir):
os.mkdir(outdir)
self.outfile2 = outdir + '/' + tail + '.png'
if os.path.isfile(self.outfile2):
os.remove(self.outfile2)
if self.hidefile2 != "None" and self.sfile != '':
if value =="ON" and str.strip(self.spass) == '':
self.buffer1.set_text("If you select the password option you must fill in the password entry!")
self.showdiag()
else:
cmd = stegprog + ' --embed --algorithm ' + self.algorithm2 + ' --messagefile ' + re.escape(self.hidefile2) + ' --coverfile ' + re.escape(self.sfile) + ' --stegofile ' + re.escape(self.outfile2)
if value2 == "ON":
cmd += ' --compress '
elif value2 == "OFF":
cmd += ' --nocompress '
if value == "ON":
cmd += ' --encrypt --password ' + self.spass
elif value == "OFF":
cmd += ' --noencrypt'
proc = Popen(cmd, shell = True, stderr=PIPE, stdout=PIPE)
line = str(proc.communicate()[1])
if str.strip(line) == '':
self.buffer1.set_text("Output file should exist here: \n" + self.outfile2)
else:
self.buffer1.set_text(line)
self.showdiag()
else:
self.buffer1.set_text("You must select a valid image file and a file to be hidden.")
self.showdiag()
def ostegextract2(self, widget):
self.sfile = self.file.get_text()
value3 = ("OFF", "ON")[self.checkbutton4.get_active()]
self.spass = self.pass3.get_text()
self.alg2 = (self.algorithm2.get_active())
self.info = self.fileinfo.get_text()
ostegattack = ("OFF", "ON")[self.passattack.get_active()]
if self.alg2 == 0:
self.algorithm3 = "RandomLSB"
elif self.alg2 == 1:
self.algorithm3 = "LSB"
head, tail = os.path.split(self.sfile)
outdir = home + tail + '/openstegextract'
if not os.path.isdir(outdir):
os.mkdir(outdir)
if self.sfile != '' and "PNG" in self.info:
self.buffer2.set_text("Please Wait \n")
self.ostegdictionary = str(self.passfilechoose.get_filename())
if ostegattack == "ON":
if self.ostegdictionary != "None":
head, tail = os.path.split(self.sfile)
outdir = home + tail + '/openstegattack'
if not os.path.isdir(outdir):
os.mkdir(outdir)
print re.escape(outdir)
master, slave = pty.openpty()
cmd = "python " + re.escape(execdir) + "/breakosteg.py " + re.escape(self.ostegdictionary) + " " + re.escape(self.sfile) + " " + re.escape(outdir)
print cmd
proc = Popen("exec " + cmd, shell=True, stdout=slave)
pid = proc.pid
def showprogress():
def hideprogress(widget):
os.system("kill " + str(pid))
self.showstatus.hide()
self.statusbutton.connect("clicked",hideprogress)
self.showstatus.show()
showprogress()
def test_io_watch(f, cond):
out = f.readline()
end_iter = self.buffer2.get_end_iter()
self.buffer2.insert(end_iter, out)
adj = self.sw.get_vadjustment()
adj.set_value(adj.get_upper() - adj.get_page_size())
if "Extracted" in out:
print out
if out == '':
return False
return True
GObject.io_add_watch(os.fdopen(master), GObject.IO_IN | GObject.IO_HUP, test_io_watch)
else:
self.buffer1.set_text("You must select a dictionary if you want to perform a dictionary attack!")
self.showdiag()
else:
if value3 == "ON" and str.strip(self.spass) == '':
self.buffer1.set_text("If you select the password option you must fill in the password entry!")
self.showdiag()
else:
cmd = stegprog + ' extract --algorithm=' + self.algorithm3 + ' --stegofile=' + re.escape(self.sfile) + ' --extractdir=' + re.escape(outdir)
if value3 == "ON":
cmd += ' --password=' + self.spass
proc = Popen(cmd, shell=True, stderr=PIPE, stdout=PIPE)
line = str(proc.communicate()[1])
self.buffer1.set_text(line)
self.showdiag()
else:
self.buffer1.set_text("You must select a valid PNG file before performing any operations. Please select a valid PNG file using the file menu!")
self.showdiag()