Repository navigation
Expand file tree
/
Copy pathOMVSSecurityChecks.java
More file actions
2482 lines (2366 loc) · 69.8 KB
/
Copy pathOMVSSecurityChecks.java
File metadata and controls
2482 lines (2366 loc) · 69.8 KB
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
import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.util.*;
/*
* Read-only, ordinary-user security checks for OMVSEnum.
*
* This class avoids active probes. Symbolic links are resolved
* only for explicit trust targets; recursive scans do not follow
* links. Every scan has a fixed root, item cap, or command timeout.
*/
final class OMVSSecurityChecks {
private static final int COMMAND_TIMEOUT = 15;
private static final int OUTPUT_LINES = 120;
private static final int WALK_CAP = 4000;
private static final LinkOption[] NOFOLLOW = {
LinkOption.NOFOLLOW_LINKS
};
private OMVSSecurityChecks() { }
static final class SafResult {
static final int GRANTED = 0;
static final int NO_DECISION = 4;
static final int DENIED = 8;
static final int UNAVAILABLE = -1;
static final int ERROR = -2;
final String safClass;
final String entity;
final String requestedAccess;
final String grantedAccess;
final int exitCode;
final String detail;
SafResult(
String safClass, String entity,
String requestedAccess, String grantedAccess,
int exitCode, String detail
) {
this.safClass = safClass;
this.entity = entity;
this.requestedAccess = requestedAccess;
this.grantedAccess = grantedAccess;
this.exitCode = exitCode;
this.detail = detail == null ? "" : detail;
}
boolean granted() {
return exitCode == GRANTED;
}
boolean noDecision() {
return exitCode == NO_DECISION;
}
boolean denied() {
return exitCode == DENIED;
}
boolean available() {
return exitCode >= 0;
}
String status() {
if (granted()) return "GRANTED";
if (noDecision()) return "NO SAF DECISION";
if (denied()) return "DENIED";
if (exitCode == UNAVAILABLE) return "UNAVAILABLE";
return "ERROR";
}
public String toString() {
String access = grantedAccess == null
? requestedAccess : grantedAccess;
return status() + " " + safClass + " " +
entity + " " + access +
(detail.isEmpty() ? "" : " (" + detail + ")");
}
}
static final class PathTrust {
final Path path;
final boolean exists;
final boolean symbolicLink;
final boolean effectivelyWritable;
final boolean writableParent;
final boolean trustedParents;
final String detail;
PathTrust(
Path path, boolean exists, boolean symbolicLink,
boolean effectivelyWritable, boolean writableParent,
boolean trustedParents, String detail
) {
this.path = path;
this.exists = exists;
this.symbolicLink = symbolicLink;
this.effectivelyWritable = effectivelyWritable;
this.writableParent = writableParent;
this.trustedParents = trustedParents;
this.detail = detail;
}
boolean replacementRisk() {
return writableParent || !trustedParents;
}
public String toString() {
return path + ": " + detail;
}
}
static SafResult checkSafAccess(
String safClass, String entity, String access
) {
return checkSafAccess(
OMVSEnum.findSafauth(), safClass, entity,
access, false, null);
}
static SafResult checkSafAccess(
String safauth, String safClass,
String entity, String access
) {
return checkSafAccess(
safauth, safClass, entity, access,
false, null);
}
static SafResult checkSafAccess(
String safauth, String safClass,
String entity, String access,
boolean vsam, String volser
) {
final String fn = "checkSafAccess";
if (safauth == null || safauth.trim().isEmpty()) {
return new SafResult(
safClass, entity, access, null,
SafResult.UNAVAILABLE, "safauth not available");
}
if (safClass == null || entity == null ||
!validAccess(access)) {
return new SafResult(
safClass, entity, access, null,
SafResult.ERROR, "invalid SAF arguments");
}
List<String> command = new ArrayList<String>();
command.add(safauth);
if (vsam) command.add("--vsam");
command.add(safClass);
command.add(entity);
command.add(access.toLowerCase(Locale.ENGLISH));
if (volser != null && !volser.trim().isEmpty())
command.add(volser);
String[] argv = command.toArray(
new String[command.size()]);
OMVSEnum.dbg(fn, Arrays.toString(argv));
OMVSEnum.CommandResult result =
OMVSEnum.execute(10, argv);
if (result.timedOut)
return new SafResult(
safClass, entity, access, null,
SafResult.ERROR, "timeout");
if (result.error != null)
return new SafResult(
safClass, entity, access, null,
SafResult.UNAVAILABLE,
result.error.getClass().getSimpleName() +
": " + safeMessage(result.error));
String detail = firstNonEmpty(
result.stderr, result.stdout);
if (result.exitCode == SafResult.GRANTED ||
result.exitCode == SafResult.NO_DECISION ||
result.exitCode == SafResult.DENIED) {
return new SafResult(
safClass, entity, access,
result.exitCode == 0
? access.toUpperCase(Locale.ENGLISH) : null,
result.exitCode, capText(detail, 8));
}
return new SafResult(
safClass, entity, access, null,
SafResult.ERROR, "unexpected exit " +
result.exitCode +
(detail.isEmpty() ? "" : ": " +
capText(detail, 8)));
}
static SafResult checkHighestSafAccess(
String safClass, String entity
) {
return checkHighestSafAccess(
OMVSEnum.findSafauth(), safClass, entity,
false, null);
}
static SafResult checkHighestSafAccess(
String safauth, String safClass, String entity
) {
return checkHighestSafAccess(
safauth, safClass, entity, false, null);
}
static SafResult checkHighestSafAccess(
String safauth, String safClass, String entity,
boolean vsam, String volser
) {
String[] levels = {
"alter", "control", "update", "read"
};
SafResult noDecision = null;
SafResult denied = null;
for (String level : levels) {
SafResult result = checkSafAccess(
safauth, safClass, entity, level,
vsam, volser);
if (result.granted()) return result;
if (result.noDecision() && noDecision == null)
noDecision = result;
else if (result.denied() && denied == null)
denied = result;
else if (!result.available()) return result;
}
// A no-decision prevents a blanket denial claim.
if (noDecision != null) return noDecision;
if (denied != null)
return new SafResult(
safClass, entity, "read", null,
SafResult.DENIED,
"all tested access levels denied; " +
"this does not prove the resource secure");
return new SafResult(
safClass, entity, "read", null,
SafResult.ERROR, "no conclusive result");
}
static PathTrust analyzePathTrust(String value) {
return analyzePathTrust(Paths.get(value));
}
static PathTrust analyzePathTrust(Path supplied) {
Path path = supplied.toAbsolutePath().normalize();
boolean exists = false;
boolean symlink = false;
boolean writable = false;
boolean writableParent = false;
boolean trustedParents = true;
StringBuilder detail = new StringBuilder();
try {
// Check the logical chain first. Top-level z/OS directories can be
// symlinks, which is context rather than a vulnerability by itself.
Path current = path.getRoot();
if (current == null)
throw new IOException("path has no root");
if (current.equals(path)) exists = true;
for (Path part : path) {
current = current.resolve(part);
if (!Files.exists(current, NOFOLLOW)) {
trustedParents = false;
append(detail, "missing component " + current);
break;
}
if (current.equals(path)) exists = true;
if (Files.isSymbolicLink(current)) {
symlink = true;
append(detail,
current.equals(path)
? "target is a symbolic link"
: "symlink component " + current);
continue;
}
if (current.equals(path)) {
continue;
} else {
boolean parentWritable = effectiveWrite(current);
if (parentWritable) {
trustedParents = false;
writableParent = true;
append(detail, "writable parent " + current);
}
}
}
if (exists) {
Path real = path.toRealPath();
writable = effectiveWrite(real);
if (writable)
append(detail, "target is effectively writable");
Path parent = real.getParent();
while (parent != null) {
if (effectiveWrite(parent)) {
trustedParents = false;
writableParent = true;
append(detail,
"writable resolved parent " + parent);
}
parent = parent.getParent();
}
}
} catch (Exception e) {
trustedParents = false;
append(detail, "analysis unavailable: " +
e.getClass().getSimpleName() + ": " +
safeMessage(e));
}
if (detail.length() == 0)
detail.append("not writable; no writable parent observed");
return new PathTrust(
path, exists, symlink, writable,
writableParent, trustedParents,
detail.toString());
}
static boolean effectiveWritablePath(Path path) {
PathTrust trust = analyzePathTrust(path);
return trust.effectivelyWritable ||
trust.writableParent;
}
static void identityHomeChecks() {
final String fn = "identityHomeChecks";
OMVSEnum.dbg(fn, "checking identity and home trust");
emitCommandInfo("Identity", 10, "id");
Path passwd = Paths.get("/etc/passwd");
Path group = Paths.get("/etc/group");
emitTrust("Identity database trust", passwd, true);
emitTrust("Identity database trust", group, true);
Map<String, List<String>> uidNames =
new LinkedHashMap<String, List<String>>();
Map<String, String[]> users =
readPasswd(passwd, uidNames, 2000);
List<String> zeroNames = uidNames.get("0");
if (zeroNames == null || zeroNames.isEmpty()) {
OMVSEnum.emit("[!]", "UID 0 identities unavailable",
"/etc/passwd was unreadable or contained no parseable UID 0.");
} else {
OMVSEnum.emit(
zeroNames.size() > 1 ? "[+]" : "[-]",
"UID 0 account names", joinValues(zeroNames));
}
StringBuilder duplicates = new StringBuilder();
int duplicateCount = 0;
for (Map.Entry<String, List<String>> entry :
uidNames.entrySet()) {
if (entry.getValue().size() < 2) continue;
if (duplicateCount++ >= 40) break;
duplicates.append("UID ").append(entry.getKey())
.append(": ").append(joinValues(entry.getValue()))
.append("\n");
}
if (duplicates.length() > 0)
OMVSEnum.emit("[+]", "Duplicate POSIX UIDs",
duplicates.toString().trim());
String homeValue = System.getenv("HOME");
String me = currentUser();
String[] posix = findUser(users, me);
if (posix == null) {
posix = new String[] {
me, "x", OMVSEnum.run("id", "-u").trim(),
OMVSEnum.run("id", "-g").trim(), "",
homeValue == null ? "" : homeValue,
firstNonEmpty(System.getenv("SHELL"), "")
};
}
if (posix != null) {
OMVSEnum.emit("[-]", "POSIX identity fields",
"user=" + me + "\nuid=" + posix[2] +
"\nhome=" + posix[5] + "\nshell=" + posix[6]);
} else {
OMVSEnum.emit("[!]", "POSIX identity unavailable",
"No parseable /etc/passwd entry for " + me + ".");
}
String lu = OMVSEnum.runTimeout(
12, "/bin/tsocmd", "LU " +
me.toUpperCase(Locale.ENGLISH));
Map<String, String> omvs = parseOmvsLu(lu);
if (!omvs.isEmpty()) {
compareIdentityField(
"HOME environment/POSIX", homeValue,
posix == null ? null : posix[5]);
compareIdentityField(
"OMVS HOME/POSIX",
omvs.get("HOME"),
posix == null ? null : posix[5]);
compareIdentityField(
"OMVS PROGRAM/POSIX shell",
omvs.get("PROGRAM"),
posix == null ? null : posix[6]);
compareIdentityField(
"OMVS UID/POSIX UID",
omvs.get("UID"),
posix == null ? null : posix[2]);
} else {
OMVSEnum.emit("[!]", "OMVS LU fields unavailable",
"LU did not expose parseable UID, HOME, or PROGRAM fields.");
}
Path uHomes = resolvedDirectory("/u");
Path homeHomes = resolvedDirectory("/home");
boolean homeRootFound = false;
if (uHomes != null) {
inspectHomeRoot(uHomes, 120);
homeRootFound = true;
}
if (homeHomes != null) {
inspectHomeRoot(homeHomes, 120);
homeRootFound = true;
}
if (!homeRootFound)
OMVSEnum.emit("[!]",
"Home-root metadata unavailable",
"Neither /u nor /home was observable.");
if (homeValue == null || homeValue.trim().isEmpty()) {
OMVSEnum.emit("[!]", "HOME unavailable",
"Identity/home checks could not determine HOME.");
return;
}
Path home = Paths.get(homeValue);
emitPersonalPathTrust(
"Home directory trust", home);
String[] names = {
".profile", ".bash_profile", ".bashrc",
".kshrc", ".sh_history", ".netrc",
".rhosts", ".forward"
};
int seen = 0;
for (String name : names) {
Path file = home.resolve(name);
if (!Files.exists(file, NOFOLLOW)) continue;
seen++;
emitPersonalPathTrust(
"Home startup/credential trust", file);
emitSensitiveMode(file);
}
Path ssh = home.resolve(".ssh");
if (Files.exists(ssh, NOFOLLOW))
emitPersonalPathTrust(
"SSH directory trust", ssh);
if (seen == 0)
OMVSEnum.emit("[-]",
"Home startup files not observed",
"Curated names only; absence is not a security conclusion.");
}
static void sshPostureChecks() {
final String fn = "sshPostureChecks";
OMVSEnum.dbg(fn, "checking SSH posture");
Path[] configs = {
Paths.get("/etc/ssh/sshd_config"),
Paths.get("/etc/sshd_config"),
Paths.get("/etc/ssh/ssh_config")
};
boolean found = false;
for (Path config : configs) {
if (!Files.exists(config, NOFOLLOW)) continue;
found = true;
emitTrust("SSH configuration trust",
config, true);
inspectSshConfiguration(config, 300, 80);
}
String homeValue = System.getenv("HOME");
if (homeValue != null) {
Path ssh = Paths.get(homeValue).resolve(".ssh");
String[] names = {
"authorized_keys", "authorized_keys2",
"known_hosts", "config", "id_rsa",
"id_dsa", "id_ecdsa", "id_ed25519"
};
for (String name : names) {
Path file = ssh.resolve(name);
if (!Files.exists(file, NOFOLLOW)) continue;
emitPersonalPathTrust(
"User SSH file trust", file);
emitSensitiveMode(file);
if (name.startsWith("authorized_keys")) {
String risky = readMatchingLines(
file, new String[] {
"command=", "environment=", "permitopen=",
"from=", "no-port-forwarding"
}, 80);
if (!risky.isEmpty())
OMVSEnum.emit("[-]",
"authorized_keys options (review context)",
risky);
}
}
}
if (!found)
OMVSEnum.emit("[!]",
"SSH server configuration unavailable",
"No curated sshd_config path was readable/present; " +
"this is not evidence SSH is disabled.");
if (OMVSEnum.thorough)
inspectOtherSshHomes();
}
private static void inspectOtherSshHomes() {
String[] roots = {"/u", "/home"};
int homes = 0;
for (String value : roots) {
Path root = resolvedDirectory(value);
if (root == null) continue;
DirectoryStream<Path> stream = null;
try {
stream = Files.newDirectoryStream(root);
for (Path home : stream) {
if (homes++ >= 100) return;
Path ssh = home.resolve(".ssh");
if (!Files.isDirectory(ssh, NOFOLLOW))
continue;
emitTrust("Other-user SSH directory trust",
ssh, true);
String[] names = {
"authorized_keys", "authorized_keys2",
"id_rsa", "id_dsa", "id_ecdsa",
"id_ed25519"
};
for (String name : names) {
Path file = ssh.resolve(name);
if (!Files.exists(file, NOFOLLOW))
continue;
emitTrust("Other-user SSH file trust",
file, true);
emitSensitiveMode(file);
}
}
} catch (Exception e) {
OMVSEnum.dbg("inspectOtherSshHomes",
value + ": " + safeMessage(e));
} finally {
closeQuietly(stream);
}
}
}
static void sensitiveConfigChecks() {
final String fn = "sensitiveConfigChecks";
OMVSEnum.dbg(fn, "checking curated sensitive files");
String[] paths = {
"/etc/profile", "/etc/environment",
"/etc/hosts", "/etc/resolv.conf",
"/etc/inetd.conf", "/etc/services",
"/etc/security/limits", "/etc/rc",
"/etc/rc.local", "/etc/syslog.conf",
"/etc/rsyslog.conf"
};
int found = 0;
for (String value : paths) {
Path path = Paths.get(value);
if (!Files.exists(path, NOFOLLOW)) continue;
found++;
emitTrust("Sensitive configuration trust",
path, true);
if (Files.isReadable(path))
OMVSEnum.emit("[-]",
"Sensitive configuration readable",
path.toString() +
" (readability is exposure context, not itself a vulnerability)");
else
OMVSEnum.emit("[-]",
"Sensitive configuration access denied",
path + " was not readable; denial does not prove secure.");
}
if (found == 0)
OMVSEnum.emit("[!]",
"Sensitive configurations unavailable",
"None of the curated paths were observed.");
}
static void capabilityChecks(boolean extendedSaf) {
final String fn = "capabilityChecks";
OMVSEnum.dbg(fn, "checking SAF capabilities");
String safauth = OMVSEnum.findSafauth();
if (safauth == null) {
OMVSEnum.emit("[!]",
"SAF capability checks unavailable",
"safauth is not compiled/available; no denial or security " +
"conclusion can be made.");
return;
}
String[][] base = {
{"FACILITY", "BPX.SUPERUSER"},
{"FACILITY", "BPX.DAEMON"},
{"FACILITY", "BPX.SERVER"},
{"FACILITY", "BPX.FILEATTR.APF"},
{"FACILITY", "BPX.FILEATTR.PROGCTL"},
{"UNIXPRIV", "SUPERUSER.FILESYS.CHOWN"},
{"UNIXPRIV", "SUPERUSER.FILESYS.MOUNT"},
{"UNIXPRIV", "SUPERUSER.PROCESS.KILL"},
{"UNIXPRIV", "SUPERUSER.SETPRIORITY"}
};
checkSafResources(safauth, base);
if (extendedSaf) {
String[][] extended = {
{"FACILITY", "BPX.JOBNAME"},
{"FACILITY", "BPX.POE"},
{"FACILITY", "BPX.WLMSERVER"},
{"FACILITY", "BPX.CONSOLE"},
{"UNIXPRIV", "SUPERUSER.FILESYS"},
{"UNIXPRIV", "SUPERUSER.PROCESS"},
{"UNIXPRIV", "SHARED.IDS"},
{"SURROGAT", "BPX.SRV.ADMIN"}
};
checkSafResources(safauth, extended);
LinkedHashSet<String> candidates =
collectCandidateIds(12);
OMVSEnum.emit("[-]",
"Extended authorization candidate IDs",
joinValues(candidates) +
"\nCapped at 12 IDs from self, /u, and visible ps.");
for (String userid : candidates) {
emitSafResult(
"Authorization check SURROGAT " +
userid + ".SUBMIT",
checkSafAccess(
safauth, "SURROGAT",
userid + ".SUBMIT", "read"));
emitSafResult(
"Authorization check SURROGAT BPX.SRV." +
userid,
checkSafAccess(
safauth, "SURROGAT",
"BPX.SRV." + userid, "read"));
emitSafResult(
"Site-dependent authorization check JESJOBS " +
userid + ".*",
checkSafAccess(
safauth, "JESJOBS",
userid + ".*", "read"));
}
} else {
OMVSEnum.emit("[-]",
"Extended SAF capability checks disabled",
"Only the curated baseline resources were checked.");
}
}
static void privilegedProcessTrustChecks() {
final String fn = "privilegedProcessTrustChecks";
OMVSEnum.dbg(fn, "correlating process paths");
OMVSEnum.CommandResult result =
OMVSEnum.execute(15, "ps", "-ef");
if (!usable(result, "Process trust checks")) return;
int checked = 0;
LinkedHashSet<String> paths =
new LinkedHashSet<String>();
for (String line : result.stdout.split("\n")) {
String trimmed = line.trim();
if (trimmed.isEmpty() ||
trimmed.toUpperCase(Locale.ENGLISH)
.contains(" UID ")) continue;
String[] fields = trimmed.split("\\s+");
String identity = fields.length > 0
? fields[0].toUpperCase(Locale.ENGLISH) : "";
String lower =
trimmed.toLowerCase(Locale.ENGLISH);
boolean privileged =
identity.equals("0") ||
identity.equals("ROOT") ||
identity.startsWith("STC") ||
identity.startsWith("DB2") ||
identity.startsWith("IMS") ||
identity.startsWith("CICS") ||
identity.startsWith("OMVS") ||
identity.startsWith("WLM") ||
lower.contains("sshd") ||
lower.contains("inetd") ||
lower.contains("syslogd");
if (!privileged) continue;
for (String field : fields) {
if (field.startsWith("/") &&
field.length() < 512) {
int end = field.indexOf(' ');
String candidate =
end < 0 ? field : field.substring(0, end);
paths.add(candidate);
break;
}
}
if (paths.size() >= 80) break;
}
for (String value : paths) {
Path path;
try {
path = Paths.get(value);
} catch (InvalidPathException e) {
continue;
}
if (!Files.exists(path, NOFOLLOW)) continue;
checked++;
emitTrust("Privileged process executable trust",
path, false);
}
if (checked == 0)
OMVSEnum.emit("[!]",
"Privileged process path correlation unavailable",
"No absolute executable paths for UID 0/root were visible; " +
"process visibility or ps formatting may be restricted.");
}
static void scheduledExecutionChecks() {
final String fn = "scheduledExecutionChecks";
OMVSEnum.dbg(fn, "checking scheduled execution");
String[] paths = {
"/etc/crontab", "/etc/cron.d",
"/var/spool/cron", "/var/spool/cron/crontabs",
"/usr/spool/cron", "/etc/at.deny",
"/etc/at.allow", "/var/spool/at",
"/etc/rc", "/etc/rc.local", "/etc/rc.d"
};
int found = 0;
LinkedHashSet<Path> commandPaths =
new LinkedHashSet<Path>();
for (String value : paths) {
Path path = Paths.get(value);
if (!Files.exists(path, NOFOLLOW)) continue;
found++;
emitTrust("Scheduled execution trust",
path, true);
if (Files.isDirectory(path, NOFOLLOW))
inspectDirectoryChildren(
"Scheduled entry trust", path, 80);
collectCommandsFromPath(
path, commandPaths, 80, 200);
}
OMVSEnum.CommandResult crontab =
OMVSEnum.execute(10, "crontab", "-l");
if (crontab.error != null || crontab.timedOut) {
OMVSEnum.emit("[!]",
"Personal crontab unavailable",
commandFailure(crontab));
} else if (crontab.exitCode == 0) {
OMVSEnum.emit("[-]", "Personal crontab readable",
"Parseable lines=" +
(crontab.stdout.trim().isEmpty() ? 0 :
Math.min(
crontab.stdout.split("\n").length, 100)) +
"; command content is not emitted.");
collectAbsolutePaths(
crontab.stdout, commandPaths, 100);
} else {
OMVSEnum.emit("[-]",
"Personal crontab denied or absent",
"crontab -l exited " + crontab.exitCode +
"; this does not establish scheduler security.");
}
if (found == 0)
OMVSEnum.emit("[!]",
"Scheduled execution paths unavailable",
"No curated cron/at paths were observable.");
int checked = 0;
for (Path command : commandPaths) {
if (checked++ >= 100) break;
emitTrust("Scheduled command trust",
command, true);
}
}
static void passiveExtendedAttributeChecks() {
final String fn = "passiveExtendedAttributeChecks";
OMVSEnum.dbg(fn, "inventorying extended attributes");
String[] roots = {
"/bin", "/usr/bin", "/usr/sbin",
"/usr/lpp", "/opt"
};
String[][] attributes = {
{"a", "APF"}, {"p", "program-control"},
{"l", "shared-library"}
};
LinkedHashMap<Path, Set<String>> inventory =
new LinkedHashMap<Path, Set<String>>();
boolean supported = false;
for (String root : roots) {
Path scanRoot = resolvedDirectory(root);
if (scanRoot == null) continue;
for (String[] attribute : attributes) {
List<Path> matches = findAttributePaths(
scanRoot.toString(), attribute[0],
250, 12);
if (matches != null) supported = true;
if (matches == null) continue;
for (Path path : matches) {
Set<String> names = inventory.get(path);
if (names == null) {
if (inventory.size() >= 500) break;
names = new LinkedHashSet<String>();
inventory.put(path, names);
}
names.add(attribute[1]);
}
}
}
int risks = 0;
for (Map.Entry<Path, Set<String>> entry :
inventory.entrySet()) {
PathTrust trust = analyzePathTrust(entry.getKey());
if (!trust.effectivelyWritable &&
!trust.replacementRisk())
continue;
risks++;
if (risks <= 100)
OMVSEnum.emit("[+]",
"Extended-attribute trust risk",
entry.getKey() + " attributes=" +
joinValues(entry.getValue()) + "\n" +
trust.detail);
}
if (!supported)
OMVSEnum.emit("[!]",
"Passive extended attribute checks inconclusive",
"Scoped find -ext inventory was unavailable; " +
"no attributes were changed.");
else
OMVSEnum.emit("[-]",
"Extended-attribute inventory summary",
"Scoped entries=" + inventory.size() +
", actionable trust risks=" + risks +
", output cap=100 risks; inventory caps: " +
"250/type/root and 500 unique paths.");
}
static void thoroughSuidChecks() {
final String fn = "thoroughSuidChecks";
OMVSEnum.dbg(fn, "bounded SUID/SGID scan");
String[] roots = {
"/bin", "/usr/bin", "/usr/sbin",
"/usr/lpp", "/opt"
};
LinkedHashMap<Path, Set<String>> inventory =
new LinkedHashMap<Path, Set<String>>();
for (String root : roots) {
Path scanRoot = resolvedDirectory(root);
if (scanRoot == null) continue;
String[][] modes = {
{"-4000", "SUID"}, {"-2000", "SGID"}
};
for (String[] mode : modes) {
List<Path> paths = findModePaths(
scanRoot.toString(), mode[0],
300, 15);
if (paths == null) continue;
for (Path path : paths) {
Set<String> names = inventory.get(path);
if (names == null) {
if (inventory.size() >= 600) break;
names = new LinkedHashSet<String>();
inventory.put(path, names);
}
names.add(mode[1]);
}
}
}
int actionable = 0;
for (Map.Entry<Path, Set<String>> entry :
inventory.entrySet()) {
Path path = entry.getKey();
PathTrust trust = analyzePathTrust(path);
if (!effectiveExecute(path) ||
(!trust.effectivelyWritable &&
!trust.replacementRisk()))
continue;
actionable++;
if (actionable <= 100)
OMVSEnum.emit("[+]",
"Actionable SUID/SGID trust risk",
path + " modes=" +
joinValues(entry.getValue()) + "\n" +
trust.detail);
}
OMVSEnum.emit("[-]", "SUID/SGID inventory summary",
"Scoped entries=" + inventory.size() +
", executable trust risks=" + actionable +
", output cap=100 risks; inventory caps: " +
"300/mode/root and 600 unique paths.");
}
static void mountExposureChecks() {
final String fn = "mountExposureChecks";
OMVSEnum.dbg(fn, "checking mount exposure");
OMVSEnum.CommandResult df =
OMVSEnum.execute(15, "df", "-kP");
if (!usable(df, "Mount exposure checks")) return;
OMVSEnum.emit("[-]", "Mounted filesystems",
capText(df.stdout, OUTPUT_LINES));
inspectMountOptions();
inspectAutomountMaps();
for (String line : df.stdout.split("\n")) {
String[] fields = line.trim().split("\\s+");
if (fields.length < 2 ||
fields[0].equalsIgnoreCase("Filesystem"))
continue;
String mount = fields[fields.length - 1];
if (mount.startsWith("/"))
emitTrust("Mount point parent trust",
Paths.get(mount), false);
}
OMVSEnum.emit("[-]",
"Mounted dataset SAF correlation",
"Reported in the files section to avoid duplicate AUTH requests.");
}
private static void inspectMountOptions() {
OMVSEnum.CommandResult result =
OMVSEnum.execute(15, "mount");
if (result.error != null ||
result.exitCode == 127) {
OMVSEnum.emit("[-]",
"Mount option inventory unavailable",
"mount is not installed; df inventory remains available.");
return;
}
if (!usable(result, "Mount option inventory"))
return;
StringBuilder remote = new StringBuilder();
StringBuilder risky = new StringBuilder();
int seen = 0;
for (String line : result.stdout.split("\n")) {
if (seen++ >= 500) break;
String lower =
line.toLowerCase(Locale.ENGLISH);
boolean isRemote =
lower.contains("nfs") ||
lower.contains("automount");
if (!isRemote) continue;
if (lineCount(remote) < 100)
remote.append(line).append("\n");
boolean writable =
lower.contains("rw") &&
!lower.contains("ro,") &&
!lower.contains("(ro");
boolean permitsSpecial =
lower.contains("suid") ||
(!lower.contains("nosuid") &&
!lower.contains("nodev"));
if (writable && permitsSpecial &&
lineCount(risky) < 100)
risky.append(line).append("\n");
}
if (remote.length() > 0)
OMVSEnum.emit("[-]", "Remote/automount inventory",
remote.toString().trim());
if (risky.length() > 0)
OMVSEnum.emit("[+]",
"Potentially writable remote mounts " +
"without visible nosuid/nodev controls",
risky.toString().trim() +
"\nTextual option classification; verify site semantics.");
}
private static void inspectAutomountMaps() {
Path etc = Paths.get("/etc");
if (!Files.isDirectory(etc)) return;
LinkedHashSet<Path> maps =
new LinkedHashSet<Path>();
Path master = etc.resolve("auto.master");
if (Files.exists(master, NOFOLLOW))
maps.add(master);
DirectoryStream<Path> stream = null;
try {
stream = Files.newDirectoryStream(etc, "auto.*");
for (Path path : stream) {
if (maps.size() >= 20) break;
maps.add(path);
}
} catch (Exception e) {
OMVSEnum.dbg("inspectAutomountMaps",
safeMessage(e));
} finally {
closeQuietly(stream);
}
LinkedHashSet<Path> targets =
new LinkedHashSet<Path>();
for (Path map : maps) {
emitTrust("Automount map trust", map, true);
collectAbsolutePathsFromFile(map, targets, 200);
}
int count = 0;
for (Path target : targets) {
if (count++ >= 50) break;
emitTrust("Automount target trust",
target, true);
}
}
static void ipcExposureChecks() {
final String fn = "ipcExposureChecks";
OMVSEnum.dbg(fn, "checking IPC visibility");
String[][] commands = {
{"ipcs", "-a"}, {"ipcs", "-m"},
{"ipcs", "-q"}, {"ipcs", "-s"}