SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 297 | Next

Shon Harris, Allen Harper, Chris Eagle, and Jonathan Ness

"Gray Hat Hacking, Second Edition"

.. one_line = line.split() # split() will separate on white space
... line_key = one_line[0]
... line_value = one_line[1]
... lines_dictionary[line_key] = line_value
... # Note: Next line is blank ( only) to break out of the for loop
...
>>> # Now we are back at python prompt with a populated dictionary
>>> lines_dictionary
{'RPC-DCOM': '10.10.20.1,10.10.20.4', 'SQL-SA-blank-pw':
'10.10.20.27,10.10.20.28'}
# Loop next over the keys and open a new file for each key
>>> for key in lines_dictionary.keys():
... targets_string = lines_dictionary[key] # value for key
... targets_list = targets_string.split(',') # break into list
... targets_number = len(targets_list)
... filename = key + '_' + str(targets_number) + '_targets'
... vuln_file = open(filename,'w')
... for vuln_target in targets_list: # for each IP in list...
... vuln_file.write(vuln_target + '\n')
... vuln_file.close()
...
>>> ^D
% ls
RPC-DCOM_2_targets targets
SQL-SA-blank-pw_2_targets
% cat SQL-SA-blank-pw_2_targets
10.10.20.27
10.10.20.28
% cat RPC-DCOM_2_targets
10.10.20.1
10.10.20.4
This example introduced a couple of new concepts. First, you now see how easy it is to
use files. open() takes two arguments. The first is the name of the file you??™d like to read or
create and the second is the access type.


Pages:
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309