maskdata.pl 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. #!/usr/bin/perl
  2. # maskdata.pl v19.1
  3. # Perl script to mask cutomer IP and user data from
  4. # files returned to Oracle.
  5. #
  6. # Please use perl 5.24 or later versions
  7. #
  8. use File::Find;
  9. use Digest::SHA qw(sha256_hex);
  10. use Digest::SHA qw(hmac_sha256_hex);
  11. use Text::ParseWords;
  12. # set encryption key
  13. my $key = 'XYZ';
  14. #
  15. # Set up needed variables.
  16. #
  17. $p_NonIpAdressRegex = qr/
  18. ([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})
  19. /x;
  20. $p_IpAdressPortRegex = qr/
  21. (((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]:[0-9]+|2[0-4][0-9]:[0-9]+|1[0-9]{2}:[0-9]+|[0-9]{1,2}:[0-9]+))
  22. /x;
  23. #
  24. #build IP regex
  25. #
  26. $p_IpAdressRegex = qr/
  27. (
  28. (?:
  29. (?: 2(?:5[0-5]|[0-4][0-9])\. )
  30. |
  31. (?: 1[0-9][0-9]\. )
  32. |
  33. (?: (?:[1-9][0-9]?|[0-9])\. )
  34. )
  35. {3}
  36. (?:
  37. (?: 2(?:5[0-5]|[0-4][0-9]) )
  38. |
  39. (?: 1[0-9][0-9] )
  40. |
  41. (?: [1-9][0-9]?|[0-9] )
  42. )
  43. )
  44. /x;
  45. $p_version = "[Vv]ersion";
  46. $p_userName = "<username>.*</username>";
  47. $p_release = "[Rr]elease";
  48. $p_desUserName = ".*password-encrypted>.*password-encrypted>";
  49. $p_wlsuser = "WLS_USER=.*";
  50. $p_wlsuserConfig = "<node-manager-username>.*</node-manager-username>";
  51. $p_wlspass = "WLS_PW=.*";
  52. $p_encPass = "<credential-encrypted>.*</credential-encrypted>";
  53. $p_port = "<listen-port>.*</listen-port>";
  54. $p_listenaddress = "<listen-address>.*</listen-address>";
  55. $p_serverprivatekey = "<server-private-key-pass-phrase-encrypted>.*</server-private-key-pass-phrase-encrypted>";
  56. $p_clusteraddress = "<cluster-address>.*</cluster-address>";
  57. $p_shellcommand = "<shell-command>.*</shell-command>";
  58. $p_constructorarg = '<constructor-arg index="0" value=".*" />';
  59. $p_beanid = '<bean id=".*" class';
  60. $p_propertyname = '<property name="url" value=".*" />';
  61. $p_weblogic_process = "-Dweblogic.management.server=.*-";
  62. $p_wls_user_name_attribute = '<wls:user-name-attribute>.*</wls:user-name-attribute>';
  63. $p_wls_principal = '<wls:principal>.*</wls:principal>';
  64. $p_wls_user_base_dn = '<wls:user-base-dn>.*</wls:user-base-dn>';
  65. $p_wls_user_from_name_filter = '<wls:user-from-name-filter>.*</wls:user-from-name-filter>';
  66. $p_wls_credential_encrypted = '<wls:credential-encrypted>.*</wls:credential-encrypted>';
  67. $p_wls_group_base_dn = '<wls:group-base-dn>.*</wls:group-base-dn>';
  68. $p_wls_username = ".management.username=.*?";
  69. $p_wls_password = ".management.password=.*?";
  70. $p_wls_username1 = ".admin.username=.*?";
  71. $p_wls_port1 = ".admin.port=.*? ";
  72. $p_composite_prop_password = '<property.*proxyPassword.*</property>';
  73. $p_jdbc_user = '<name>user</name>\n<value>.*</value>';
  74. my $dirname = $ARGV[0];
  75. my $dataoption = $ARGV[1];
  76. my $filename = "";
  77. my $replacetextIP = "Ip Address or port masked.";
  78. my $replacetextPort = "<listen-port><!-- listen port has been masked --></listen-port>";
  79. my $replacetextListen = "<listen-address><!-- listen address has been masked --></listen-address>";
  80. my $replacetextUser = "<credential-encrypted><!-- User or password has been masked --></credential-encrypted>";
  81. my $replacetextserverprivatekey = "<server-private-key-pass-phrase-encrypted><!-- server-private-key-pass-phrase-encrypted has been masked --></server-private-key-pass-phrase-encrypted>";
  82. my $replacetextclusteraddress = "<cluster-address><!-- cluster-address has been masked --></cluster-address>";
  83. my $replacetextshellcommand = "<shell-command><!-- shell-command has been masked --></shell-command>";
  84. my $replacetextconstructorarg = '<constructor-arg index="0" value="value has been masked" />';
  85. my $replacetextbeanid = '<bean id="id has been masked" class';
  86. my $replacetextpropertyname = '<property name="url" value="url has been masked" />';
  87. my $replacetextWeblogicProcess = "-Dweblogic.management.server=Server Name masked.-";
  88. my $replacetext_wls_user_name_attribute = '<wls:user-name-attribute><!-- user-name-attribute has been masked --></wls:user-name-attribute>';
  89. my $replacetext_wls_principal = '<wls:principal><!-- user principal been masked --></wls:principal>';
  90. my $replacetext_wls_user_base_dn = '<wls:user-base-dn><!-- user-base-dn has been masked --></wls:user-base-dn>';
  91. my $replacetext_wls_user_from_name_filter = '<wls:user-from-name-filter><!-- user-from-name-filter has been masked --></wls:user-from-name-filter>';
  92. my $replacetext_wls_credential_encrypted = '<wls:credential-encrypted><!-- credential-encrypted has been masked --></wls:credential-encrypted>';
  93. my $replacetext_wls_group_base_dn = '<wls:group-base-dn><!-- wls:group-base-dn has been masked --></wls:group-base-dn>';
  94. my $replacetext_wls_username = '.management.username=<!-- User or password has been masked --> ';
  95. my $replacetext_wls_password = '.management.password=<!-- User or password has been masked --> ';
  96. my $replacetext_wls_username1 = '.admin.username=<!-- User or password has been masked --> ';
  97. my $replacetext_wls_port1 = '.admin.port=<!-- listen port has been masked --> ';
  98. my $replacetext_composite_prop_password = '<property name="oracle.webservices.proxyPassword">ProxyPassword has been masked.</property>';
  99. my $replacetext_jdbc_user = '<name>user</name>\n<value>JDBC Property Password has been masked.</value>';
  100. my @outLines;
  101. my $line;
  102. find(\&mask, $dirname);
  103. sub mask_column256 {
  104. my ($col) = @_;
  105. $position = $col - 1;
  106. if ( @mylist[$position] =~ "^\"" ) {
  107. @mylist[$position] = "\"".sha256_hex(substr(@mylist[$position], 1, length(@mylist[$position])-2))."\"";
  108. }
  109. else {
  110. @mylist[$position] = sha256_hex(@mylist[$position]);
  111. }
  112. }
  113. sub mask_column {
  114. my ($col) = @_;
  115. $position = $col - 1;
  116. my $stripped_string = @mylist[$position];
  117. $stripped_string =~ s/"//g; #remove the double quotes (") to see if the string is empty, like ""
  118. if ( @mylist[$position] !~ /\n/ ) {
  119. if ( length($stripped_string) > 0 ) {
  120. if ( @mylist[$position] =~ "^\"" ) {
  121. # first step: lowercase(USER) then hash sha256_hex, then uppercase(all)
  122. @mylist[$position] = "\"".uc sha256_hex(substr(lc @mylist[$position], 1, length(@mylist[$position])-2))."\"";
  123. # second step: hash sha256_hex with provided key, uppercase, then prefix with OBF_
  124. @mylist[$position] = "\"OBF_".uc hmac_sha256_hex((substr(@mylist[$position], 1, length(@mylist[$position])-2)), $key)."\"";
  125. }
  126. else {
  127. # first step: lowercase(USER) then hash sha256_hex, then uppercase(all)
  128. @mylist[$position] = uc sha256_hex(lc @mylist[$position]);
  129. # second step: hash sha256_hex with provided key, uppercase, then prefix with OBF_
  130. @mylist[$position] = "OBF_".uc hmac_sha256_hex((@mylist[$position]), $key);
  131. }
  132. }
  133. }
  134. }
  135. sub mask_ip {
  136. $outline2 = $outline;
  137. while( $outline2 =~ m/$p_NonIpAdressRegex/ ) {
  138. $outline2 =~ s/$p_NonIpAdressRegex//g;
  139. }
  140. if ( $outline2 =~ m/$p_IpAdressRegex/ ) {
  141. # first step: lowercase(USER) then hash sha256_hex, then uppercase(all)
  142. $replacetextIP = "OBF_".uc sha256_hex(lc $1);
  143. # second step: hash sha256_hex with provided key, uppercase, then prefix with OBF_
  144. $replacetextIP = "OBF_".uc hmac_sha256_hex($replacetextIP, $key);
  145. $outline =~ s/$1/$replacetextIP/g;
  146. }
  147. }
  148. sub mask_users_wlsnup {
  149. $p_wlsnup_username = qr/
  150. (WLSNUP_SHA1:)(.+)
  151. /x;
  152. if ( not -l $filename ) {
  153. # make sure the file is not a symlink
  154. #try opening file matched from find
  155. #
  156. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  157. #
  158. #loop throught file looking for match
  159. #
  160. while ( $line = <FILE> ) {
  161. $outline=$line;
  162. if ( $outline =~ m/$p_wlsnup_username/ ) {
  163. $replacetextWLSNUP = "OBF_".uc sha256_hex(lc $2);
  164. # second step: hash sha256_hex with provided key, uppercase, then prefix with OBF_
  165. $replacetextWLSNUP = "OBF_".uc hmac_sha256_hex($replacetextWLSNUP, $key);
  166. $outline =~ s/$2/$replacetextWLSNUP/g;
  167. $outline =~ s/WLSNUP_SHA1/WLSNUP_SHA2/g;
  168. }
  169. push(@outLines, $outline);
  170. }
  171. close FILE;
  172. }
  173. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  174. print ( OUTFILE @outLines );
  175. close ( OUTFILE );
  176. undef( @outLines );
  177. }
  178. sub mask_users_csv {
  179. if ( not -l $filename ) {
  180. # make sure the file is not a symlink
  181. #try opening file matched from find
  182. #
  183. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  184. #
  185. #loop throught file looking for match
  186. #
  187. while ( $line = <FILE> ) {
  188. $outline = "";
  189. if ( $line =~ "," ) {
  190. $mylist =[];
  191. @mylist = parse_line(q{,}, 1, $line);
  192. if (@mylist[0] ne "AUDIT_ID" ) { if ($#mylist>=1) { mask_column(2) } };
  193. foreach $x (@mylist) { $outline = $outline.",".$x }
  194. # remove the first comma from the line
  195. $outline =~ s/^.//;
  196. } else {
  197. $outline=$line;
  198. }
  199. if ( uc($dataoption) =~ "ALL" ) { mask_ip() };
  200. push(@outLines, $outline);
  201. }
  202. close FILE;
  203. }
  204. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  205. print ( OUTFILE @outLines );
  206. close ( OUTFILE );
  207. undef( @outLines );
  208. }
  209. sub mask_segments_csv {
  210. if ( not -l $filename ) {
  211. # make sure the file is not a symlink
  212. #try opening file matched from find
  213. #
  214. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  215. #
  216. #loop throught file looking for match
  217. #
  218. while ( $line = <FILE> ) {
  219. $outline = "";
  220. if ( $line =~ "," ) {
  221. $mylist =[];
  222. @mylist = parse_line(q{,}, 1, $line);
  223. if (@mylist[0] ne "AUDIT_ID" ) { if ($#mylist>=1) { mask_column(2) } };
  224. foreach $x (@mylist) { $outline = $outline.",".$x }
  225. # remove the first comma from the line
  226. $outline =~ s/^.//;
  227. } else {
  228. $outline=$line;
  229. }
  230. if ( uc($dataoption) =~ "ALL" ) { mask_ip() };
  231. push(@outLines, $outline);
  232. }
  233. close FILE;
  234. }
  235. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  236. print ( OUTFILE @outLines );
  237. close ( OUTFILE );
  238. undef( @outLines );
  239. }
  240. sub mask_session_csv {
  241. if ( not -l $filename ) {
  242. # make sure the file is not a symlink
  243. #try opening file matched from find
  244. #
  245. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  246. #
  247. #loop throught file looking for match
  248. #
  249. while ( $line = <FILE> ) {
  250. $outline = "";
  251. if ( $line =~ "," ) {
  252. $mylist =[];
  253. #@mylist = split(",",$line);
  254. @mylist = parse_line(q{,}, 1, $line);
  255. if (@mylist[0] ne "AUDIT_ID" ) {
  256. if ($#mylist>=3) { mask_column(4) };
  257. if ($#mylist>=7) { mask_column(8) };
  258. if ($#mylist>=8) { mask_column(9) };
  259. }
  260. foreach $x (@mylist) { $outline = $outline.",".$x }
  261. # remove the first comma from the line
  262. $outline =~ s/^.//;
  263. } else {
  264. $outline=$line;
  265. }
  266. if ( uc($dataoption) =~ "ALL" ) { mask_ip() };
  267. push(@outLines, $outline);
  268. }
  269. close FILE;
  270. }
  271. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  272. print ( OUTFILE @outLines );
  273. close ( OUTFILE );
  274. undef( @outLines );
  275. }
  276. sub mask_oraproducts_csv {
  277. if ( not -l $filename ) {
  278. # make sure the file is not a symlink
  279. #try opening file matched from find
  280. #
  281. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  282. #
  283. #loop throught file looking for match
  284. #
  285. while ( $line = <FILE> ) {
  286. $outline = "";
  287. if ( $line =~ "^GREPEBS" ) {
  288. $mylist =[];
  289. @mylist = parse_line(q{,}, 1, $line);
  290. if (@mylist[5] ne "LAST_DDL_TIME") { if ($#mylist>=1) { mask_column(2) } };
  291. foreach $x (@mylist) { $outline = $outline.",".$x }
  292. # remove the first comma from the line
  293. $outline =~ s/^.//;
  294. } elsif ( $line =~ "^GREPME" ) {
  295. $mylist =[];
  296. @mylist = parse_line(q{,}, 1, $line);
  297. if (@mylist[6] eq "EBS" && @mylist[7] eq "EBS_SCHEMAS") { if ($#mylist>=10) { mask_column(11) } };
  298. if (@mylist[6] eq "EBS" && @mylist[7] eq "SYSTEM.FND_ORACLE_USERID") { if ($#mylist>=11) { mask_column(12) } ; if ($#mylist>=15) { mask_column(16) } };
  299. if (@mylist[6] eq "EBS" && @mylist[7] eq "EBS_SPECIFIC_OBJECTS") { if ($#mylist>=12) { mask_column(13) } };
  300. if (@mylist[6] eq "OWB" && @mylist[7] eq "OBJECTS_DEPLOYED") { if ($#mylist>=10) { mask_column(11) } };
  301. if (@mylist[6] eq "OWB" && @mylist[7] eq "JOBS_RUN") { if ($#mylist>=10) { mask_column(11) } };
  302. if (@mylist[6] eq "OWB" && @mylist[7] eq "FEATURES") { if ($#mylist>=10) { mask_column(11) } ; if ($#mylist>=11) { mask_column(12) } };
  303. if (@mylist[6] eq "OWB" && @mylist[7] eq "LOCATIONS") { if ($#mylist>=10) { mask_column(11) } ; if ($#mylist>=11) { mask_column(12) } };
  304. if (@mylist[6] eq "OWB" && @mylist[7] eq "MAPPINGS_TLO") { if ($#mylist>=10) { mask_column(11) } ; if ($#mylist>=11) { mask_column(12) } };
  305. foreach $x (@mylist) { $outline = $outline.",".$x }
  306. # remove the first comma from the line
  307. $outline =~ s/^.//;
  308. }
  309. elsif ( $line =~ "^END OF SCRIPT" ) {
  310. $outline=$line;
  311. }
  312. else {
  313. #$outline="\n";
  314. #$outline=$line;
  315. }
  316. if ( uc($dataoption) =~ "ALL" ) { mask_ip() };
  317. push(@outLines, $outline);
  318. }
  319. close FILE;
  320. }
  321. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  322. print ( OUTFILE @outLines );
  323. close ( OUTFILE );
  324. undef( @outLines );
  325. }
  326. sub mask_summary_csv {
  327. if ( not -l $filename ) {
  328. # make sure the file is not a symlink
  329. #try opening file matched from find
  330. #
  331. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  332. print ( OUTFILE "replaced\n" );
  333. close ( OUTFILE );
  334. }
  335. }
  336. sub mask_options_csv {
  337. if ( not -l $filename ) {
  338. # make sure the file is not a symlink
  339. #try opening file matched from find
  340. #
  341. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  342. #
  343. #loop throught file looking for match
  344. #
  345. while ( $line = <FILE> ) {
  346. $outline = "";
  347. if ( $line =~ "^GREPME" ) {
  348. $mylist =[];
  349. @mylist = parse_line(q{,}, 1, $line);
  350. if (@mylist[6] eq "DBA_REGISTRY" && @mylist[7] eq "9i_r2") { if ($#mylist>=14) { mask_column(15) } };
  351. if (@mylist[6] eq "PARTITIONING" && @mylist[7] eq "PARTITIONED_SEGMENTS") { if ($#mylist>=10) { mask_column(11) } };
  352. if (@mylist[6] eq "PARTITIONING" && @mylist[7] eq "OLAP_AWS_SEGMENTS") { if ($#mylist>=10) { mask_column(11) } ; if ($#mylist>=14) { mask_column(15) } };
  353. if (@mylist[6] eq "PARTITIONING" && @mylist[7] eq "PARTITION_OBJ_RECYCLEBIN") { if ($#mylist>=10) { mask_column(11) } };
  354. if (@mylist[6] eq "PARTITIONING" && @mylist[7] eq "DBA_FLASHBACK_ARCHIVE_TABLES+INDEXES+LOBS") { if ($#mylist>=10) { mask_column(11) } ; if ($#mylist>=14) { mask_column(15) } };
  355. if (@mylist[6] eq "PARTITIONING" && @mylist[7] eq "ALL_CHANGE_TABLES") { if ($#mylist>=11) { mask_column(12) } ; if ($#mylist>=13) { mask_column(14) } };
  356. if (@mylist[6] eq "PARTITIONING" && @mylist[7] eq "SCHEMA_VERSION_REGISTRY") { if ($#mylist>=15) { mask_column(16) } };
  357. if (@mylist[6] eq "OLAP" && @mylist[7] eq "OLAPSYS.DBA\$OLAP_CUBES") { if ($#mylist>=10) { mask_column(11) } };
  358. if (@mylist[6] eq "OLAP" && @mylist[7] eq "DBA_CUBES") { if ($#mylist>=10) { mask_column(11) } };
  359. if (@mylist[6] eq "OLAP" && @mylist[7] eq "ANALYTIC_WORKSPACES") { if ($#mylist>=10) { mask_column(11) } };
  360. if (@mylist[6] eq "DATA_MINING" && @mylist[7] eq "11g+.DBA_MINING_MODELS") { if ($#mylist>=10) { mask_column(11) } };
  361. if (@mylist[6] eq "SPATIAL" && @mylist[7] eq "ALL_SDO_GEOM_METADATA") { if ($#mylist>=10) { mask_column(11) } };
  362. if (@mylist[6] eq "ADVANCED_SECURITY" && @mylist[7] eq "COLUMN_ENCRYPTION") { if ($#mylist>=10) { mask_column(11) } };
  363. if (@mylist[6] eq "ADVANCED_SECURITY" && @mylist[7] eq "SECUREFILES_ENCRYPTION") { if ($#mylist>=11) { mask_column(12) } };
  364. if (@mylist[6] eq "ADVANCED_COMPRESSION" && @mylist[7] eq "TABLE_COMPRESSION") { if ($#mylist>=11) { mask_column(12) } };
  365. if (@mylist[6] eq "ADVANCED_COMPRESSION" && @mylist[7] eq "SECUREFILES_COMPRESSION_AND_DEDUPLICATION") { if ($#mylist>=11) { mask_column(12) } };
  366. if (@mylist[6] eq "ADVANCED_COMPRESSION" && @mylist[7] eq "DBA_FLASHBACK_ARCHIVE_TABLES") { if ($#mylist>=11) { mask_column(12) } };
  367. if (@mylist[6] eq "DATABASE_VAULT" && @mylist[7] eq "DVSYS_SCHEMA") { if ($#mylist>=10) { mask_column(11) } };
  368. if (@mylist[6] eq "DATABASE_VAULT" && @mylist[7] eq "DVF_SCHEMA") { if ($#mylist>=10) { mask_column(11) } };
  369. if (@mylist[6] eq "DB_IN_MEMORY" && @mylist[7] eq "INMEMORY_ENABLED_TABLES") { if ($#mylist>=11) { mask_column(12) } };
  370. if (@mylist[6] eq "DB_IN_MEMORY" && @mylist[7] eq "GV\$IM_SEGMENTS") { if ($#mylist>=13) { mask_column(14) } };
  371. if (@mylist[6] eq "OEM" && @mylist[7] eq "GRID_CONTROL+11g") { if ($#mylist>=17) { mask_column(18) } };
  372. if (@mylist[6] eq "OEM" && @mylist[7] eq "MGMT_LICENSES") { if ($#mylist>=10) { mask_column(11) } };
  373. if (@mylist[6] eq "OEM" && @mylist[7] eq "MGMT_LICENSE_CONFIRMATION") { if ($#mylist>=11) { mask_column(12) } };
  374. if (@mylist[6] eq "OEM" && @mylist[7] eq "DBA_ADVISOR_TASKS") { if ($#mylist>=11) { mask_column(12) } };
  375. if (@mylist[6] eq "OEM" && @mylist[7] eq "DBA_SQLSET") { if ($#mylist>=12) { mask_column(13) } };
  376. if (@mylist[6] eq "OEM" && @mylist[7] eq "DBA_SQLSET_REFERENCES") { if ($#mylist>=12) { mask_column(13) } ; if ($#mylist>=14) { mask_column(15) } };
  377. if (@mylist[6] eq "AUDIT_VAULT*" && @mylist[7] eq "AVSYS_SCHEMA") { if ($#mylist>=10) { mask_column(11) } };
  378. if (@mylist[6] eq "CONTENT_AND_RECORDS" && @mylist[7] eq "CONTENT_SCHEMA") { if ($#mylist>=10) { mask_column(11) } };
  379. if (@mylist[6] eq "OWB" && @mylist[7] eq "REPOSITORY") { if ($#mylist>=10) { mask_column(11) } };
  380. if (@mylist[6] eq "EXTRA_INFO" && @mylist[7] eq "V\$SESSION") { if ($#mylist>=12) { mask_column(13) }; if ($#mylist>=16) { mask_column(17) }; if ($#mylist>=17) { mask_column(18) }; };
  381. if (@mylist[6] eq "USER_PRIVS" && @mylist[7] eq "USER") { if ($#mylist>=10) { mask_column(11) } };
  382. if (@mylist[6] eq "USER_PRIVS" && @mylist[7] eq "USER_SYS_PRIVS") { if ($#mylist>=10) { mask_column(11) } };
  383. if (@mylist[6] eq "USER_PRIVS" && @mylist[7] eq "USER_ROLE_PRIVS") { if ($#mylist>=10) { mask_column(11) } ; if ($#mylist>=11) { mask_column(12) } };
  384. if (@mylist[6] eq "USER_PRIVS" && @mylist[7] eq "ROLE_SYS_PRIVS") { if ($#mylist>=10) { mask_column(11) } };
  385. if (@mylist[6] eq "PARTITIONING" && @mylist[7] eq "DBA_USERS.ORACLE_MAINTAINED") { if ($#mylist>=10) { mask_column(11) } };
  386. if (@mylist[6] eq "PARTITIONING" && @mylist[7] eq "DBA_USERS.IMPLICIT") { if ($#mylist>=10) { mask_column(11) } };
  387. if (@mylist[6] eq "ADVANCED_SECURITY" && @mylist[7] eq "REDACTION_POLICIES") { if ($#mylist>=10) { mask_column(11) } };
  388. if (@mylist[6] eq "ADVANCED_COMPRESSION" && @mylist[7] eq "DBA_INDEXES.COMPRESSION") { if ($#mylist>=10) { mask_column(11) }; if ($#mylist>=12) { mask_column(13) } };
  389. foreach $x (@mylist) { $outline = $outline.",".$x }
  390. # remove the first comma from the line
  391. $outline =~ s/^.//;
  392. }
  393. elsif ( $line =~ "\\*\\*\\* EXTRA INFO \\*\\*\\* Troubleshooting" ) {
  394. $outline=$line;
  395. }
  396. else {
  397. #$outline="\n";
  398. #$outline=$line;
  399. }
  400. if ( uc($dataoption) =~ "ALL" ) { mask_ip() };
  401. push(@outLines, $outline);
  402. }
  403. close FILE;
  404. }
  405. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  406. print ( OUTFILE @outLines );
  407. close ( OUTFILE );
  408. undef( @outLines );
  409. }
  410. sub mask {
  411. $filename=$File::Find::name;
  412. #print "$filename\n";
  413. ##########################################
  414. # FMW section #
  415. ##########################################
  416. if ( (/\.xml$/) || (/\.bea$/) || (/\.txt$/) || (/\.properties$/) || (/\.sh$/) || (/\.log$/) ){
  417. if ( not -l $filename ) {
  418. # make sure the file is not a symlink
  419. print "Masking $dataoption from FMW output file: $filename\n";
  420. #try opening file matched from find
  421. #
  422. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  423. #
  424. #loop throught file looking for match
  425. #
  426. while ( $line = <FILE> ) {
  427. if ( $dataoption =~ "user" ) {
  428. if ( $line =~ m/$p_userName/ ) {
  429. $line =~ s/$p_userName/$replacetextUser/g;
  430. } elsif ( $line =~ m/$p_desUserName/ ) {
  431. $line =~ s/$p_desUserName/$replacetextUser/g;
  432. } elsif ( $line =~ m/$p_wlsuser/ ) {
  433. $line =~ s/$p_wlsuser/$replacetextUser/g;
  434. } elsif ( $line =~ m/$p_wlsuserConfig/ ) {
  435. $line =~ s/$p_wlsuserConfig/$replacetextUser/g;
  436. } elsif ( $line =~ m/$p_wlspass/ ) {
  437. $line =~ s/$p_wlspass/$replacetextUser/g;
  438. } elsif ( $line =~ m/$p_encPass/ ) {
  439. $line =~ s/$p_encPass/$replacetextUser/g;
  440. } elsif ( $line =~ m/$p_composite_prop_password/ ) {
  441. $line =~ s/$p_composite_prop_password/$replacetext_composite_prop_password/g;
  442. } elsif ( $line =~ m/$p_jdbc_user/ ) {
  443. $line =~ s/$p_jdbc_user/$replacetext_jdbc_user/g;
  444. } elsif ( $line =~ m/$p_wls_username(^|\s)/ || $line =~ m/$p_wls_password(^|\s)/ || $line =~ m/$p_wls_username1(^|\s)/ ) {
  445. $line =~ s/$p_wls_username(^|\s)/$replacetext_wls_username/g;
  446. $line =~ s/$p_wls_username1(^|\s)/$replacetext_wls_username1/g;
  447. $line =~ s/$p_wls_password(^|\s)/$replacetext_wls_password/g;
  448. }
  449. } elsif ( $dataoption =~ "IP" ) {
  450. if ( $line =~ m/$p_IpAdressPortRegex/ ) {
  451. $line =~ s/$p_IpAdressPortRegex/$replacetextIP/g;
  452. } elsif ($line =~ m/$p_IpAdressRegex/ && $line !~ m/$p_NonIpAdressRegex/ && $line !~ m/$p_version/ && $line !~ m/$p_release/ ) {
  453. $line =~ s/$p_IpAdressRegex/$replacetextIP/g;
  454. } elsif ( $line =~ m/$p_port/ ) {
  455. $line =~ s/$p_port/$replacetextPort/g;
  456. } elsif ( $line =~ m/$p_listenaddress/ ) {
  457. $line =~ s/$p_listenaddress/$replacetextListen/g;
  458. }
  459. } else {
  460. #Find IP match but ignore lines with version in it so config.xml, registry.xml versions are left alone.
  461. if ( $line =~ m/$p_IpAdressRegex/ && $line !~ m/$p_NonIpAdressRegex/ && $line !~ m/$p_version/ && $line !~ m/$p_release/ ) {
  462. $line =~ s/$p_IpAdressRegex/$replacetextIP/g;
  463. if ( $line =~ m/$p_wls_username(^|\s)/ || $line =~ m/$p_wls_password(^|\s)/ || $line =~ m/$p_wls_username1(^|\s)/ || $line =~ m/$p_wls_port1(^|\s)/) {
  464. $line =~ s/$p_wls_username1(^|\s)/$replacetext_wls_username1/g;
  465. $line =~ s/$p_wls_username(^|\s)/$replacetext_wls_username/g;
  466. $line =~ s/$p_wls_password(^|\s)/$replacetext_wls_password\n/g;
  467. $line =~ s/$p_wls_port1(^|\s)/$replacetext_wls_port1/g;
  468. }
  469. } elsif ( $line =~ m/$p_userName/ ) {
  470. $line =~ s/$p_userName/$replacetextUser/g;
  471. } elsif ( $line =~ m/$p_desUserName/ ) {
  472. $line =~ s/$p_desUserName/$replacetextUser/g;
  473. } elsif ( $line =~ m/$p_wlsuser/ ) {
  474. $line =~ s/$p_wlsuser/$replacetextUser/g;
  475. } elsif ( $line =~ m/$p_wlsuserConfig/ ) {
  476. $line =~ s/$p_wlsuserConfig/$replacetextUser/g;
  477. } elsif ( $line =~ m/$p_wlspass/ ) {
  478. $line =~ s/$p_wlspass/$replacetextUser/g;
  479. } elsif ( $line =~ m/$p_encPass/ ) {
  480. $line =~ s/$p_encPass/$replacetextUser/g;
  481. } elsif ( $line =~ m/$p_port/ ) {
  482. $line =~ s/$p_port/$replacetextPort/g;
  483. } elsif ( $line =~ m/$p_listenaddress/ ) {
  484. $line =~ s/$p_listenaddress/$replacetextIP/g;
  485. } elsif ( $line =~ m/$p_serverprivatekey/ ) {
  486. $line =~ s/$p_serverprivatekey/$replacetextserverprivatekey/g;
  487. } elsif ( $line =~ m/$p_clusteraddress/ ) {
  488. $line =~ s/$p_clusteraddress/$replacetextclusteraddress/g;
  489. } elsif ( $line =~ m/$p_shellcommand/ ) {
  490. $line =~ s/$p_shellcommand/$replacetextshellcommand/g;
  491. } elsif ( $line =~ m/$p_constructorarg/ ) {
  492. $line =~ s/$p_constructorarg/$replacetextconstructorarg/g;
  493. } elsif ( $line =~ m/$p_beanid/ ) {
  494. $line =~ s/$p_beanid/$replacetextbeanid/g;
  495. } elsif ( $line =~ m/$p_propertyname/ ) {
  496. $line =~ s/$p_propertyname/$replacetextpropertyname/g;
  497. } elsif ( $line =~ m/$p_weblogic_process/ ) {
  498. $line =~ s/$p_weblogic_process/$replacetextWeblogicProcess/g;
  499. } elsif ( $line =~ m/$p_wls_user_name_attribute/ ) {
  500. $line =~ s/$p_wls_user_name_attribute/$replacetext_wls_user_name_attribute/g;
  501. } elsif ( $line =~ m/$p_wls_principal/ ) {
  502. $line =~ s/$p_wls_principal/$replacetext_wls_principal/g;
  503. } elsif ( $line =~ m/$p_wls_user_base_dn/ ) {
  504. $line =~ s/$p_wls_user_base_dn/$replacetext_wls_user_base_dn/g;
  505. } elsif ( $line =~ m/$p_wls_user_from_name_filter/ ) {
  506. $line =~ s/$p_wls_user_from_name_filter/$replacetext_wls_user_from_name_filter/g;
  507. } elsif ( $line =~ m/$p_wls_credential_encrypted/ ) {
  508. $line =~ s/$p_wls_credential_encrypted/$replacetext_wls_credential_encrypted/g;
  509. } elsif ( $line =~ m/$p_wls_group_base_dn/ ) {
  510. $line =~ s/$p_wls_group_base_dn/$replacetext_wls_group_base_dn/g;
  511. } elsif ( $line =~ m/$p_composite_prop_password/ ) {
  512. $line =~ s/$p_composite_prop_password/$replacetext_composite_prop_password/g;
  513. } elsif ( $line =~ m/$p_jdbc_user/ ) {
  514. $line =~ s/$p_jdbc_user/$replacetext_jdbc_user/g;
  515. } elsif ( $line =~ m/$p_wls_username(^|\s)/ || $line =~ m/$p_wls_username1(^|\s)/ || $line =~ m/$p_wls_password(^|\s)/ ) {
  516. $line =~ s/$p_wls_username1(^|\s)/$replacetext_wls_username1/g;
  517. $line =~ s/$p_wls_username(^|\s)/$replacetext_wls_username/g;
  518. $line =~ s/$p_wls_password(^|\s)/$replacetext_wls_password\n/g;
  519. $line =~ s/$p_wls_port1(^|\s)/$replacetext_wls_port1/g;
  520. }
  521. }
  522. push(@outLines, $line);
  523. }
  524. close FILE;
  525. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  526. print ( OUTFILE @outLines );
  527. close ( OUTFILE );
  528. undef( @outLines );
  529. if (/WLS_NUP\.txt$/) { mask_users_wlsnup(); }
  530. }
  531. } elsif (/\.csv$/) {
  532. ##########################################
  533. # EBS section #
  534. ##########################################
  535. if ((/FND_USER\.csv$/) || (/WF_USER_ROLE_ASSIGNMENTS.csv$/) || (/WF_LOCAL_USER_ROLES.csv$/)) {
  536. #print "EBS1";
  537. print "Masking $dataoption from EBS output file: $filename\n";
  538. if ( $dataoption =~ "IP"){
  539. print "\tSkipping file\n";
  540. } elsif ( $dataoption =~ "user" ) {
  541. #try opening file matched from find
  542. #
  543. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  544. #
  545. #loop throught file looking for match
  546. #
  547. $column_masked=0; #store here the number of the column which needs to be masked
  548. while ( $line = <FILE> ) {
  549. # EBS part will not be masked for IP bu only for: user, all
  550. $outline = "";
  551. $encrypted_username = "";
  552. if ( $line =~ "," ) {
  553. #mask usernames
  554. $mylist =[];
  555. $cnt=0; #count here all the columns from the row split by comma
  556. $rcnt=0; #store here the current column number
  557. if ($column_masked==0) {
  558. @mylist = split(",",$line);
  559. #find the column number which needs to be masked
  560. foreach $x (@mylist) {
  561. ++$cnt;
  562. $x=~ s/[\^'*||\~||]*//g; # get rid of the special delimiters/chars
  563. if ($x eq "USER_NAME") {
  564. $column_masked=$cnt;
  565. }
  566. }
  567. #print "column to be masked=$column_masked\n";
  568. $outline=$line;
  569. } else {
  570. @mylist = split(/(?:,\^\~\*\~\^)/,$line);
  571. $rcnt=0;
  572. foreach $x (@mylist) {
  573. ++$rcnt;
  574. #print "Elementul $rcnt este: $x\n";
  575. if ($rcnt==$column_masked) {
  576. #print "original=$x\n";
  577. $x=~ s/[\^'*||\~||]*//g;
  578. #print "modified=$x\n";
  579. # first step: lowercase(USER) then hash sha256_hex, then uppercase(all)
  580. $encrypted_username = uc sha256_hex(lc $x);
  581. # second step: hash sha256_hex with provided key, uppercase, then prefix with OBF_
  582. $encrypted_username = "OBF_".uc hmac_sha256_hex($encrypted_username, $key);
  583. $outline = $outline.",^~*~^".$encrypted_username."^~*~^";
  584. #print "$outline\n";
  585. } else {
  586. #print "$x\n";
  587. if ($rcnt==1) {
  588. $outline = $x;
  589. } else {
  590. $outline = $outline.",^~*~^".$x;
  591. }
  592. }
  593. }
  594. }
  595. } else {
  596. $outline=$line;
  597. }
  598. push(@outLines, $outline);
  599. }
  600. close FILE;
  601. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  602. print ( OUTFILE @outLines );
  603. close ( OUTFILE );
  604. undef( @outLines );
  605. } else {
  606. #try opening file matched from find
  607. #
  608. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  609. #
  610. #loop throught file looking for match
  611. #
  612. $column_masked=0; #store here the number of the column which needs to be masked
  613. while ( $line = <FILE> ) {
  614. # EBS part will not be masked for IP bu only for: user, all
  615. $outline = "";
  616. $encrypted_username = "";
  617. if ( $line =~ "," ) {
  618. #mask usernames
  619. $mylist =[];
  620. $cnt=0; #count here all the columns from the row split by comma
  621. $rcnt=0; #store here the current column number
  622. if ($column_masked==0) {
  623. @mylist = split(",",$line);
  624. #find the column number which needs to be masked
  625. foreach $x (@mylist) {
  626. ++$cnt;
  627. $x=~ s/[\^'*||\~||]*//g; # get rid of the special delimiters/chars
  628. if ($x eq "USER_NAME") {
  629. $column_masked=$cnt;
  630. }
  631. }
  632. #print "column to be masked=$column_masked\n";
  633. $outline=$line;
  634. } else {
  635. @mylist = split(/(?:,\^\~\*\~\^)/,$line);
  636. $rcnt=0;
  637. foreach $x (@mylist) {
  638. ++$rcnt;
  639. #print "Elementul $rcnt este: $x\n";
  640. if ($rcnt==$column_masked) {
  641. #print "original=$x\n";
  642. $x=~ s/[\^'*||\~||]*//g;
  643. #print "modified=$x\n";
  644. # first step: lowercase(USER) then hash sha256_hex, then uppercase(all)
  645. $encrypted_username = uc sha256_hex(lc $x);
  646. # second step: hash sha256_hex with provided key, uppercase, then prefix with OBF_
  647. $encrypted_username = "OBF_".uc hmac_sha256_hex($encrypted_username, $key);
  648. $outline = $outline.",^~*~^".$encrypted_username."^~*~^";
  649. #print "$outline\n";
  650. } else {
  651. #print "$x\n";
  652. if ($rcnt==1) {
  653. $outline = $x;
  654. } else{
  655. $outline = $outline.",^~*~^".$x;
  656. }
  657. }
  658. }
  659. }
  660. } else {
  661. $outline=$line;
  662. }
  663. #just in case, mask any IP address found in the files
  664. mask_ip();
  665. push(@outLines, $outline);
  666. }
  667. close FILE;
  668. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  669. print ( OUTFILE @outLines );
  670. close ( OUTFILE );
  671. undef( @outLines );
  672. }
  673. } else {
  674. ###############################################
  675. # Database section #
  676. ###############################################
  677. #print "DB";
  678. print "Masking $dataoption from DB output file: $filename\n";
  679. if ( $dataoption =~ "user" ) {
  680. if (/users\.csv$/) { mask_users_csv() }
  681. elsif (/segments\.csv$/) { mask_segments_csv() }
  682. elsif (/session\.csv$/) { mask_session_csv() }
  683. elsif (/oraproducts\.csv$/) { mask_oraproducts_csv() }
  684. elsif (/summary\.csv$/) { mask_summary_csv() }
  685. elsif (/options\.csv$/) { mask_options_csv() }
  686. } elsif ( $dataoption =~ "IP" ) {
  687. if ( not -l $filename ) {
  688. # make sure the file is not a symlink
  689. #try opening file matched from find
  690. #
  691. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  692. #
  693. #loop throught file looking for match
  694. #dbip
  695. while ( $line = <FILE> ) {
  696. $outline=$line;
  697. while( $outline =~ m/$p_NonIpAdressRegex/ ) {
  698. $outline =~ s/$p_NonIpAdressRegex//g;
  699. }
  700. $outline2 = $outline;
  701. if ( $outline2 =~ m/$p_IpAdressRegex/ ) {
  702. # first step: lowercase(USER) then hash sha256_hex, then uppercase(all)
  703. $replacetextIP = "OBF_".uc sha256_hex(lc $1);
  704. # second step: hash sha256_hex with provided key, uppercase, then prefix with OBF_
  705. $replacetextIP = "OBF_".uc hmac_sha256_hex($replacetextIP, $key);
  706. $outline =~ s/$1/$replacetextIP/g;
  707. }
  708. $outline=$line;
  709. #print $line;
  710. push(@outLines, $outline);
  711. }
  712. close FILE;
  713. }
  714. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  715. print ( OUTFILE @outLines );
  716. close ( OUTFILE );
  717. undef( @outLines );
  718. } else {
  719. # $dataoption =~ "all"
  720. if (/users\.csv$/) { mask_users_csv() }
  721. elsif (/segments\.csv$/) { mask_segments_csv() }
  722. elsif (/session\.csv$/) { mask_session_csv() }
  723. elsif (/oraproducts\.csv$/) { mask_oraproducts_csv() }
  724. elsif (/summary\.csv$/) { mask_summary_csv() }
  725. elsif (/options\.csv$/) { mask_options_csv() }
  726. else {
  727. if ( not -l $filename ) {
  728. # make sure the file is not a symlink
  729. #try opening file matched from find
  730. #
  731. open (FILE, $filename ) || print "Can't open $filename: $!\n";
  732. #
  733. #loop throught file looking for match
  734. #dbip
  735. while ( $line = <FILE> ) {
  736. $outline=$line;
  737. while( $outline =~ m/$p_NonIpAdressRegex/ ) {
  738. $outline =~ s/$p_NonIpAdressRegex//g;
  739. }
  740. if ( $outline =~ m/$p_IpAdressRegex/ ) {
  741. # first step: lowercase(USER) then hash sha256_hex, then uppercase(all)
  742. $replacetextIP = "OBF_".uc sha256_hex(lc $1);
  743. # second step: hash sha256_hex with provided key, uppercase, then prefix with OBF_
  744. $replacetextIP = "OBF_".uc hmac_sha256_hex($replacetextIP, $key);
  745. $line =~ s/$1/$replacetextIP/g;
  746. }
  747. push(@outLines, $line);
  748. }
  749. close FILE;
  750. }
  751. open ( OUTFILE, ">$filename" ) || print "Can't open $filename: $!\n";
  752. print ( OUTFILE @outLines );
  753. close ( OUTFILE );
  754. undef( @outLines );
  755. }
  756. }
  757. }
  758. }
  759. }