0

I'm trying to write a simple script that takes a list of words I've created in a text file on linux and runs it through a program that checks the word against a steganography extractor.

The program (steghide) uses the following syntax in the command:

steghide --extract -p {password here} -sf {filename here}

I've been able to call the file and set up a for loop for the words in the list, but can not find a way to input the word from that iteration into each command.

Here's how I've been trying to work it.

import os
import sys

script, filename = argv
filename2 = sys.open(filename)

for word in filename2:
    os.system('steghide --extract -p [want to put something here] -sf stegfilename')

I'm on a controlled box and can't download anything beyond what I already have. Any help is appreciated.

Update:

I got it to work. But now I'm trying to get it to exit out if it finds the correct answer. I am just having a hard time getting Python to read the output. Here's what I have so far.

`import subprocess from sys import argv

script, filename = argv passes = filename

with open(passes) as f: for line in f: proc = subprocess.popen(['steghide', '--extract', '-p' line.strip(), '-sf', 'stegged file name'],stdout = subprocess.PIPE) stdout = proc.communicate()[0] output = proc.stdout.readline()

    if 'wrote' in output:
        print 'YOU FOUND IT!'
        break
    else:
        print line`

5 Answers 5

1

This is a good time to learn string formating options in Python. They let you insert values dynamically into a string. An example:

"This {0} is an example".format([1,2,3])
>>>> "This [1,2,3] is an example"

In this particular case, you want to do

value = 'foo' # the item you want to insert - replace with list, number, etc.
...
for word in filename2:
    os.system('steghide --extract -p {0} -sf stegfilename'.format(value))

This will insert the value into your string, and then call steghide on that string.

Sign up to request clarification or add additional context in comments.

Comments

1

Use the subprocess module instead; it gives you more options/control and os.system() is deprecated.

import subproces
with open(filename, "r") as f:
    # assumes that you have one word per line
    for line in f:
        subprocess.call(['steghide', '--extract', '-p', line.strip(), '-sf', stegfilename])
        # or if you want the output of running Niels Provos' cool, old tool :)
        cmd_output = subprocess.check_output(['steghide', '--extract', '-p', line.strip(), '-sf', stegfilename])

2 Comments

I got it to work, but now I'm trying to get it to exit once it finds the correct password. Here's what I have so far. import subprocess from sys import argv script, filename = argv passes = filename with open(passes) as f: for line in f: proc = subprocess.popen(['steghide', '--extract', '-p' line.strip(), '-sf', 'stegged file name'],stdout = subprocess.PIPE) stdout = proc.communicate()[0] output = proc.stdout.readline() if 'wrote' in output: print 'YOU FOUND IT!' break else: print line
@Brad steghide follows C/Unix conventions and returns 0 if successful, 1 if not. Use that along with subprocess.call to break on success (subprocess.call returns the return code of the process). No need for subprocess.PIPE, proc.communicate()[0] etc.
1

Use subprocess.check_call passing a list of args:

from subprocess import check_call


for word in map(str.rstrip, filename2):    
    check_call(['steghide', "--extract", "-p", word, "-sf", "stegfilename'"])

Comments

0

String formatting is the subject here.

import os
import sys

script, filename = argv
filename2 = sys.open(filename)

for word in filename2:
    os.system('steghide --extract -p ' +[want to put something here]+ '-sf stegfilename')

Comments

0

To join all elements of a list in a string, try python join:

'  '.join(your_variable)

Example:

var = ['t', 't', 't', 't', 't', 't'] 
joined = ' '.join(var)
print(joined)
print(type(joined))

t t t t t t

class 'str'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.