-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathOMVSEnum.java
More file actions
2254 lines (2087 loc) · 57.2 KB
/
Copy pathOMVSEnum.java
File metadata and controls
2254 lines (2087 loc) · 57.2 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.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
// License: GPL 3.0
// Author: Soldier of FORTRAN / @mainframed767
// z/OS USS Local Enumeration & Privilege Escalation
// Based on OMVSEnum.sh
// To compile: javac OMVSEnum.java
// To run: java -jar OMVSEnum.jar [options]
public class OMVSEnum {
// ---- config ----------------------------------------
static boolean debugMode = false;
static boolean quietMode = false;
static boolean thorough = false;
static PrintWriter report = null;
static String reportFile = null;
static int threadCount = 2;
static boolean filesWithMatches = false;
static boolean caseSensitive = false;
static boolean contentRequested = false;
static boolean activeProbes = false;
static boolean extendedSaf = false;
static Set<String> onlySections = null;
static Set<String> skippedSections =
new HashSet<String>();
static List<Path> searchRoots =
new ArrayList<Path>();
static List<SearchRule> searchRules =
new ArrayList<SearchRule>();
static final List<String> SECTION_ORDER =
Arrays.asList(
"system", "user", "environment", "capability",
"network", "services", "jobs", "software",
"files", "audit", "hfs", "chown", "racf",
"content");
static final Set<String> ACTIVE_SECTIONS =
new HashSet<String>(
Arrays.asList("files", "hfs", "chown"));
static final ThreadLocal<StringBuilder>
SECTION_OUTPUT =
new ThreadLocal<StringBuilder>();
static final SimpleDateFormat DF =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// ---- output helpers --------------------------------
static synchronized void dbg(
String fn, String msg
) {
if (!debugMode) return;
String ts = DF.format(new Date());
System.err.println(
"[DBG " + ts + "][" + fn + "] " + msg);
}
static void section(String title) {
if (quietMode) return;
println(
"\n################################################");
println("# " + title);
println(
"################################################");
}
// sev: "[-]" info, "[+]" finding, "[!]" warn
static void emit(
String sev, String label, String val
) {
if (quietMode && sev.equals("[-]")) return;
String line = sev + " " + label;
if (val != null && !val.trim().isEmpty())
line += ":\n" + indent(val.trim());
println(line);
}
static String indent(String s) {
StringBuilder sb = new StringBuilder();
for (String l : s.split("\n")) {
sb.append(" ").append(l).append("\n");
}
// trim trailing newline
int len = sb.length();
if (len > 0 && sb.charAt(len - 1) == '\n')
sb.setLength(len - 1);
return sb.toString();
}
static synchronized void println(String s) {
StringBuilder captured = SECTION_OUTPUT.get();
if (captured != null) {
captured.append(s).append("\n");
return;
}
System.out.println(s);
if (report != null) {
report.println(s);
}
}
// ---- command execution -----------------------------
static final class CommandResult {
final String stdout;
final String stderr;
final int exitCode;
final boolean timedOut;
final Exception error;
CommandResult(
String stdout, String stderr, int exitCode,
boolean timedOut, Exception error
) {
this.stdout = stdout;
this.stderr = stderr;
this.exitCode = exitCode;
this.timedOut = timedOut;
this.error = error;
}
}
static final class StreamCollector
implements Runnable {
private final InputStream input;
private final StringBuilder text =
new StringBuilder();
StreamCollector(InputStream input) {
this.input = input;
}
public void run() {
try {
BufferedReader reader =
new BufferedReader(
new InputStreamReader(input));
try {
String line;
while ((line = reader.readLine()) != null)
text.append(line).append("\n");
} finally {
reader.close();
}
} catch (IOException e) {
// The process may close streams while timing out.
}
}
String text() {
return text.toString().trim();
}
}
static String run(String... cmd) {
return runTimeout(30, cmd);
}
static String runTimeout(
int secs, String... cmd
) {
CommandResult result =
execute(secs, cmd);
debugCommand(cmd, result);
return result.stdout;
}
static CommandResult execute(
int secs, String... cmd
) {
Process process = null;
try {
process = new ProcessBuilder(cmd).start();
StreamCollector stdout =
new StreamCollector(process.getInputStream());
StreamCollector stderr =
new StreamCollector(process.getErrorStream());
Thread outThread =
new Thread(stdout, "omvsenum-command-out");
Thread errThread =
new Thread(stderr, "omvsenum-command-err");
outThread.setDaemon(true);
errThread.setDaemon(true);
outThread.start();
errThread.start();
boolean done =
process.waitFor(secs, TimeUnit.SECONDS);
if (!done) {
process.destroyForcibly();
process.waitFor(2, TimeUnit.SECONDS);
}
outThread.join(2000);
errThread.join(2000);
int exit = done ? process.exitValue() : -1;
return new CommandResult(
stdout.text(), stderr.text(), exit,
!done, null);
} catch (Exception e) {
if (process != null)
process.destroyForcibly();
return new CommandResult(
"", "", -1, false, e);
}
}
static int runExitCode(String... cmd) {
CommandResult result = execute(30, cmd);
debugCommand(cmd, result);
return result.exitCode;
}
static void debugCommand(
String[] cmd, CommandResult result
) {
if (!debugMode) return;
String joined = Arrays.toString(cmd);
if (result.error != null)
dbg("command", joined + " failed: " +
result.error.getMessage());
else if (result.timedOut)
dbg("command", joined + " timed out");
else if (result.exitCode != 0)
dbg("command", joined + " exit " +
result.exitCode +
(result.stderr.isEmpty() ? "" :
": " + result.stderr));
}
static String tso(String cmd) {
dbg("tso", "tsocmd " + cmd);
String out = run("/bin/tsocmd", cmd);
return cleanTso(cmd, out);
}
// Strip tsocmd command echo (first line)
// and ACF2 informational banner lines so
// they don't appear in emitted output or
// trigger false-positive findings
static String cleanTso(
String cmd, String out
) {
if (out.isEmpty()) return out;
StringBuilder sb = new StringBuilder();
String[] lines = out.split("\n");
boolean first = true;
for (String l : lines) {
if (first) {
first = false;
// tsocmd echoes the command as line 1
if (l.trim().equalsIgnoreCase(
cmd.trim())) continue;
}
// ACF2 logonid banner - informational
// noise on every tsocmd call on ACF2
if (l.contains("ACF0C038")) continue;
sb.append(l).append("\n");
}
return sb.toString().trim();
}
static String sysvar(String var) {
return runTimeout(10, "sysvar", var);
}
static final class SearchRule {
final String expression;
final boolean jclOnly;
SearchRule(
String expression, boolean jclOnly
) {
this.expression = expression;
this.jclOnly = jclOnly;
}
}
static final class ContentResult {
final String output;
final long matches;
ContentResult(String output, long matches) {
this.output = output;
this.matches = matches;
}
}
static void contentSearch() {
if (!contentRequested) return;
section("Content Search");
int flags = caseSensitive ? 0
: Pattern.CASE_INSENSITIVE;
final List<Pattern> patterns =
new ArrayList<Pattern>();
for (SearchRule rule : searchRules)
patterns.add(Pattern.compile(
rule.expression, flags));
if (searchRoots.isEmpty())
searchRoots.add(Paths.get("/"));
long matches = 0;
List<ContentResult> results =
searchContentRoots(patterns);
for (ContentResult result : results) {
appendSectionOutput(result.output);
matches += result.matches;
}
if (matches == 0)
emit("[-]", "No content matches found",
null);
}
static List<ContentResult> searchContentRoots(
final List<Pattern> patterns
) {
List<ContentResult> results =
new ArrayList<ContentResult>();
if (threadCount == 1 ||
searchRoots.size() == 1) {
for (Path root : searchRoots)
results.add(captureContentRoot(
root, patterns));
return results;
}
ExecutorService executor = null;
List<Future<ContentResult>> futures =
new ArrayList<Future<ContentResult>>();
try {
executor = Executors.newFixedThreadPool(
Math.min(threadCount, searchRoots.size()));
for (final Path root : searchRoots) {
futures.add(executor.submit(
new Callable<ContentResult>() {
public ContentResult call() {
return captureContentRoot(
root, patterns);
}
}));
}
for (int i = 0; i < futures.size(); i++) {
try {
results.add(futures.get(i).get());
} catch (Exception e) {
dbg("contentSearch",
"root worker failed: " +
e.getMessage());
results.add(captureContentRoot(
searchRoots.get(i), patterns));
}
}
} catch (Throwable error) {
dbg("contentSearch",
"root workers unavailable: " +
error.getMessage());
results.clear();
for (Path root : searchRoots)
results.add(captureContentRoot(
root, patterns));
} finally {
if (executor != null)
executor.shutdownNow();
}
return results;
}
static ContentResult captureContentRoot(
Path root, List<Pattern> patterns
) {
StringBuilder buffer = new StringBuilder();
StringBuilder previous =
SECTION_OUTPUT.get();
SECTION_OUTPUT.set(buffer);
long[] matches = {0};
try {
scanContentRoot(root, patterns, matches);
} finally {
if (previous == null)
SECTION_OUTPUT.remove();
else
SECTION_OUTPUT.set(previous);
}
return new ContentResult(
buffer.toString(), matches[0]);
}
static void appendSectionOutput(String text) {
if (text == null || text.isEmpty()) return;
StringBuilder captured = SECTION_OUTPUT.get();
if (captured != null)
captured.append(text);
else
writeCaptured(text);
}
static void scanContentRoot(
Path suppliedRoot, final List<Pattern> patterns,
final long[] matches
) {
Path requested =
suppliedRoot.toAbsolutePath().normalize();
final Path root;
try {
root = Files.isSymbolicLink(requested)
? requested.toRealPath() : requested;
} catch (Exception e) {
dbg("contentSearch",
"cannot resolve " + requested + ": " +
e.getMessage());
return;
}
try {
Files.walkFileTree(root,
new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(
Path file, BasicFileAttributes attrs
) {
if (!attrs.isRegularFile() ||
attrs.isSymbolicLink() ||
Files.isSymbolicLink(file) ||
!Files.isReadable(file))
return FileVisitResult.CONTINUE;
searchContentFile(
file, patterns, matches);
return FileVisitResult.CONTINUE;
}
public FileVisitResult visitFileFailed(
Path file, IOException error
) {
dbg("contentSearch",
"cannot read " + file + ": " +
error.getMessage());
return FileVisitResult.CONTINUE;
}
});
} catch (Exception e) {
dbg("contentSearch",
"walk failed for " + root + ": " +
e.getMessage());
}
}
static void searchContentFile(
Path file, List<Pattern> patterns,
long[] matches
) {
try {
if (isProbablyBinary(file)) return;
boolean isJcl = file.getFileName()
.toString().toLowerCase()
.endsWith(".jcl");
BufferedReader reader =
new BufferedReader(
new FileReader(file.toFile()));
try {
String line;
long lineNumber = 0;
while ((line = reader.readLine()) != null) {
lineNumber++;
boolean found = false;
for (int i = 0;
i < searchRules.size(); i++) {
SearchRule rule = searchRules.get(i);
if (rule.jclOnly && !isJcl)
continue;
if (patterns.get(i).matcher(line).find()) {
found = true;
break;
}
}
if (!found) continue;
matches[0]++;
if (filesWithMatches) {
println("[+] " + file);
return;
}
println("[+] " + file + ":" +
lineNumber + ": " + line);
}
} finally {
reader.close();
}
} catch (Exception e) {
dbg("contentSearch",
"cannot search " + file + ": " +
e.getMessage());
}
}
static boolean isProbablyBinary(Path file)
throws IOException {
InputStream input =
new BufferedInputStream(
new FileInputStream(file.toFile()));
try {
byte[] sample = new byte[4096];
int count = input.read(sample);
if (count <= 0) return false;
int controls = 0;
for (int i = 0; i < count; i++) {
int value = sample[i] & 0xff;
if (value == 0) return true;
if (value < 32 && value != '\n' &&
value != '\r' && value != '\t')
controls++;
}
return controls > count / 3;
} finally {
input.close();
}
}
// ---- modules ---------------------------------------
static void systemInfo() {
final String FN = "systemInfo";
section("System Information");
dbg(FN, "uname -Ia");
String uname = run("uname", "-Ia");
if (!uname.isEmpty())
emit("[-]", "Kernel information", uname);
dbg(FN, "hostname");
String host = run("hostname");
if (!host.isEmpty())
emit("[-]", "Hostname", host);
// z/OS sysvar calls
String[][] svars = {
{"SYSNAME", "LPAR Name"},
{"SYSOSLVL", "OS Level (ZxvvrrmmL)"},
{"SYSVER", "System Version"},
{"UNIXVER", "Unix Version"},
{"SYSR1", "IPL Volume Serial"},
{"SYSALVL", "Architecture Level"},
{"SYSCLONE", "System Shortname (SYSCLONE)"},
{"SYSPLEX", "Sysplex Name"},
{"ADCDLVL", "ADCD Version (if present)"},
};
for (String[] sv : svars) {
dbg(FN, "sysvar " + sv[0]);
String v = sysvar(sv[0]);
if (!v.isEmpty())
emit("[-]", sv[1], v);
}
}
static void userInfo() {
final String FN = "userInfo";
section("User / Group Information");
dbg(FN, "id");
String id = run("id");
if (!id.isEmpty())
emit("[-]", "Current user/group (POSIX)", id);
dbg(FN, "tsocmd LU");
String lu = tso("LU");
if (!lu.isEmpty()) {
// Detect ESM type from LU output
if (lu.contains("IRR418I") ||
lu.toUpperCase()
.contains("RACF PRODUCT DISABLED")) {
emit("[!]",
"RACF is DISABLED - system is likely " +
"running ACF2 or TSS as ESM", null);
} else {
emit("[-]", "RACF user profile (LU)", lu);
String luUpper = lu.toUpperCase();
if (luUpper.contains("SPECIAL"))
emit("[+]",
"User has RACF SPECIAL attribute " +
"(RACF administrator)", null);
if (luUpper.contains("OPERATIONS"))
emit("[+]",
"User has RACF OPERATIONS attribute " +
"(can read any dataset)", null);
if (luUpper.contains("AUDITOR"))
emit("[+]",
"User has RACF AUDITOR attribute",
null);
}
}
dbg(FN, "tsocmd TSS WHOAMI");
String tsswho = tso("TSS WHOAMI");
if (!tsswho.isEmpty() &&
!tsswho.contains("IKJ56500I"))
emit("[-]", "TSS user info", tsswho);
OMVSSecurityChecks.esmParityChecks();
dbg(FN, "who");
String who = run("who");
if (!who.isEmpty())
emit("[-]", "Other logged-on users", who);
// This authentication probe can create audit records and
// is therefore explicitly opt-in.
if (activeProbes) {
dbg(FN, "testing su -s (BPX.SUPERUSER)");
try {
ProcessBuilder pb =
new ProcessBuilder("su", "-s");
pb.redirectErrorStream(true);
Process p = pb.start();
p.getOutputStream().close();
// drain output
InputStream is = p.getInputStream();
byte[] buf = new byte[4096];
while (is.read(buf) != -1) { /* drain */ }
is.close();
boolean done =
p.waitFor(10, TimeUnit.SECONDS);
if (!done) {
p.destroyForcibly();
p.waitFor(2, TimeUnit.SECONDS);
emit("[!]",
"su -s timed out; result is unknown",
null);
} else if (p.exitValue() == 0) {
emit("[+]",
"su -s succeeded without password " +
"(BPX.SUPERUSER likely permitted or " +
"RACF permits su to root)", null);
} else {
emit("[-]",
"su -s without password: denied " +
"(exit " + p.exitValue() + ")", null);
}
} catch (Exception e) {
dbg(FN, "su check failed: "
+ e.getMessage());
}
}
// Default RACF group users via LG
dbg(FN, "tsocmd LG (default group)");
String lg = tso("LG");
if (!lg.isEmpty()) {
String[] lines = lg.split("\n");
int userLine = -1;
for (int i = 0; i < lines.length; i++) {
if (lines[i].toUpperCase()
.contains("USER(S)=")) {
userLine = i;
break;
}
}
if (userLine >= 0) {
StringBuilder users =
new StringBuilder();
for (int i = userLine + 1;
i < lines.length; i++) {
String l = lines[i].trim();
if (!l.isEmpty() &&
!l.contains("CONNECT") &&
!l.contains("REVOKE"))
users.append(l).append("\n");
}
if (users.length() > 0)
emit("[-]",
"Default RACF group users",
users.toString().trim());
}
}
// /u directory permissions
dbg(FN, "ls -Alp /u/");
String udirperms = run("ls", "-Alp", "/u/");
if (!udirperms.isEmpty())
emit("[-]",
"/u directory permissions", udirperms);
// sshd_config root login check
dbg(FN, "checking sshd_config");
try {
BufferedReader reader =
new BufferedReader(new FileReader(
"/etc/ssh/sshd_config"));
try {
String line;
while ((line = reader.readLine()) != null) {
int comment = line.indexOf('#');
String setting = (comment >= 0
? line.substring(0, comment) : line)
.trim();
String[] fields =
setting.split("\\s+");
if (fields.length >= 2 &&
fields[0].equalsIgnoreCase(
"PermitRootLogin") &&
fields[1].equalsIgnoreCase("yes")) {
emit("[+]",
"sshd: PermitRootLogin yes",
setting);
}
}
} finally {
reader.close();
}
} catch (Exception e) {
dbg(FN, "sshd_config not readable");
}
// Home directory contents
dbg(FN, "home directory contents");
String home = System.getenv("HOME");
if (home != null) {
String hc = run("ls", "-Alsk", home);
if (!hc.isEmpty())
emit("[-]",
"Home directory contents", hc);
}
// SSH key files (thorough only)
if (thorough) {
dbg(FN, "find SSH key files in /u");
String sshkeys = runTimeout(60,
"find", "/u/",
"(", "-name", "id_dsa*",
"-o", "-name", "id_rsa*",
"-o", "-name", "known_hosts",
"-o", "-name", "authorized_keys",
")",
"-exec", "ls", "-la", "{}", ";"
);
if (!sshkeys.isEmpty())
emit("[+]",
"SSH key/host files found in /u",
sshkeys);
}
// Writable files not owned by us (thorough)
if (thorough) {
dbg(FN,
"find writable files not owned by us");
String me = run("whoami");
String notours = runTimeout(120,
"find", "/",
"!", "-user", me,
"-writable", "-type", "f",
"-exec", "ls", "-al", "{}", ";"
);
if (!notours.isEmpty())
emit("[-]",
"Writable files not owned by " + me,
notours);
}
OMVSSecurityChecks.identityHomeChecks();
OMVSSecurityChecks.sshPostureChecks();
}
static void environmentalInfo() {
final String FN = "environmentalInfo";
section("Environment");
dbg(FN, "env");
String env = run("env");
if (!env.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (String l : env.split("\n")) {
if (!l.startsWith("LS_COLORS"))
sb.append(l).append("\n");
}
emit("[-]",
"Environment variables",
sb.toString().trim());
}
dbg(FN, "PATH");
String path = System.getenv("PATH");
if (path != null)
emit("[-]", "PATH", path);
// Writable PATH entries = hijacking risk
dbg(FN, "checking PATH for writable dirs");
if (path != null) {
Set<String> writable =
new LinkedHashSet<String>();
for (String entry : path.split(":", -1)) {
String dir = entry.trim();
// Empty PATH entries mean the current directory,
// just like an explicit "." entry.
if (dir.isEmpty()) dir = ".";
File d = new File(dir);
if (d.exists() &&
d.isDirectory() &&
d.canWrite()) {
writable.add(dir);
}
}
if (!writable.isEmpty())
emit("[+]",
"Writable directories in PATH " +
"(PATH hijacking possible)",
joinLines(writable));
}
dbg(FN, "umask");
String umask =
run("/bin/sh", "-c", "umask");
if (!umask.isEmpty())
emit("[-]", "umask value", umask);
OMVSSecurityChecks.sensitiveConfigChecks();
}
static String joinLines(
Collection<String> values
) {
StringBuilder text = new StringBuilder();
for (String value : values) {
if (text.length() > 0) text.append("\n");
text.append(value);
}
return text.toString();
}
static void networkingInfo() {
final String FN = "networkingInfo";
section("Networking");
dbg(FN, "netstat -h (interfaces)");
String nic = run("netstat", "-h");
if (!nic.isEmpty())
emit("[-]", "Network interfaces", nic);
dbg(FN, "netstat -R ALL (ARP)");
String arp = run("netstat", "-R", "ALL");
if (!arp.isEmpty())
emit("[-]", "ARP table", arp);
dbg(FN, "netstat -r (routes)");
String routes = run("netstat", "-r");
if (!routes.isEmpty())
emit("[-]", "Routes", routes);
dbg(FN, "netstat (connections)");
String ns = run("netstat");
if (!ns.isEmpty()) {
StringBuilder listen =
new StringBuilder();
StringBuilder estab =
new StringBuilder();
StringBuilder udp =
new StringBuilder();
for (String l : ns.split("\n")) {
String u = l.toUpperCase();
// skip header lines
if (u.contains("PROTO") ||
u.contains("ACTIVE"))
continue;
if (u.contains("UDP"))
udp.append(l).append("\n");
else if (u.contains("LISTEN"))
listen.append(l).append("\n");
else if (!l.trim().isEmpty())
estab.append(l).append("\n");
}
if (listen.length() > 0)
emit("[-]", "Listening TCP",
listen.toString().trim());
if (estab.length() > 0)
emit("[-]", "Established TCP",
estab.toString().trim());
if (udp.length() > 0)
emit("[-]", "UDP",
udp.toString().trim());
}
dbg(FN, "dnsdomainname");
String dns = run("dnsdomainname");
if (!dns.isEmpty())
emit("[-]", "DNS domain name", dns);
OMVSSecurityChecks.mountExposureChecks();
OMVSSecurityChecks.networkCorrelationChecks();
}
static void servicesInfo() {
final String FN = "servicesInfo";
section("Services / Processes");
dbg(FN, "ps -ef");
String me = run("whoami");
String myUid = run("id", "-u");
String psef = run("ps", "-ef");
if (!psef.isEmpty()) {
boolean canSeeAll = false;
for (String l : psef.split("\n")) {
// skip header
if (l.contains("UID")) continue;
// if a line belongs to someone else
String[] fields =
l.trim().split("\\s+");
if (fields.length > 0 &&
!fields[0].equals(me) &&
!fields[0].equals(myUid)) {
canSeeAll = true;
break;
}
}
if (canSeeAll) {
emit("[+]",
"Can list ALL processes " +
"(elevated privilege indicator)",
psef);
} else {
emit("[-]",
"Process listing (own procs only)",
psef);
}
} else {
emit("[!]",
"ps -ef returned no output " +
"(permission denied?)", null);
}
dbg(FN, "/etc/inetd.conf");
try {
byte[] raw = Files.readAllBytes(
Paths.get("/etc/inetd.conf"));
String inetd = new String(raw).trim();
if (!inetd.isEmpty())
emit("[-]",
"/etc/inetd.conf contents", inetd);
} catch (Exception e) {
dbg(FN, "/etc/inetd.conf not readable");
}
OMVSSecurityChecks.privilegedProcessTrustChecks();
if (thorough)
OMVSSecurityChecks.ipcExposureChecks();
}
static void softwareInfo() {
final String FN = "softwareInfo";
section("Software / Compilers");
String[] usefulBins = {
"nc", "netcat", "wget", "nmap",
"gcc", "python", "python3", "curl",
"perl", "ruby", "socat", "telnet",
"ftp", "sftp", "ssh", "openssl"
};
String[] compilers = {
"c89", "c99", "xlc", "cc", "c++"
};
dbg(FN, "checking useful binaries");
StringBuilder found = new StringBuilder();
for (String b : usefulBins) {
String w = run("which", b);
if (!w.isEmpty())
found.append(w).append("\n");
}
if (found.length() > 0)
emit("[-]", "Useful binaries found",
found.toString().trim());
else
emit("[-]",
"No notable useful binaries found",
null);
dbg(FN, "checking compilers");
StringBuilder comps = new StringBuilder();
for (String c : compilers) {
String w = run("which", c);
if (!w.isEmpty())
comps.append(w).append("\n");
}
// Search /usr/lpp/java for javac
dbg(FN, "find javac in /usr/lpp/java");
String javac = runTimeout(60,
"find", "/usr/lpp/java",
"-name", "javac", "-type", "f");
if (!javac.isEmpty())
comps.append(javac).append("\n");
if (comps.length() > 0)
emit("[-]", "Compilers found",
comps.toString().trim());
else
emit("[-]", "No compilers found", null);