Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. Dec 2 00:14:09 ftp1 ftpd[743]: USER testing1
  2. Dec 2 00:14:09 ftp1 ftpd[743]: FTP LOGIN FROM 192.168.0.2 [192.168.0.2], testing1
  3. Dec 2 00:30:08 ftp1 ftpd[1261]: USER testing1
  4. Dec 2 00:30:09 ftp1 ftpd[1261]: FTP LOGIN FROM 192.168.0.4 [192.168.0.4], testing1
  5. Dec 2 01:12:33 ftp1 ftpd[11804]: USER testing1
  6. Dec 2 01:12:33 ftp1 ftpd[11804]: FTP LOGIN FROM 192.168.0.2 [192.168.0.2], testing1
  7.  
  8. Dec 1 23:59:03 ftp1 ftpd[4152]: USER testing1
  9. Dec 1 23:59:03 ftp1 ftpd[4152]: PASS password
  10. Dec 1 23:59:03 ftp1 ftpd[4152]: FTP LOGIN FROM 192.168.0.02 [192.168.0.2], testing1
  11. Dec 1 23:59:03 ftp1 ftpd[4152]: PWD
  12. Dec 1 23:59:03 ftp1 ftpd[4152]: CWD /test/data/
  13. Dec 1 23:59:03 ftp1 ftpd[4152]: TYPE Image
  14.  
  15. $VAR1 = {
  16. '743' => [
  17. '00:1'
  18. ],
  19. '20687' => [
  20. '01:3'
  21. ],
  22. '27186' => [
  23. '15:3'
  24. ],
  25. '6929' => [
  26. '12:0'
  27. ],
  28. '24771' => [
  29. '09:0'
  30. ],
  31. '11804' => [
  32. '01:1'
  33. ],
  34. '27683' => [
  35. '08:3'
  36. ],
  37. '14976' => [
  38. '04:3'
  39. ],
  40. };
  41.  
  42. # -------------------------------------------------------
  43. # Extract PIDs and Time from lines, take out doubles
  44. # -------------------------------------------------------
  45. my $infile3 = 'output.txt';
  46. my %pids;
  47. my $found;
  48. my $var;
  49.  
  50. open (INPUT2, $infile3) or die "Couldn't read $infile3.n";
  51.  
  52. while (my $line = <INPUT2>) {
  53. if($line =~ /(d{2}):(d)/ ) {
  54. my $hhmm = $1 . ":" . $2;
  55. if ($line =~ /ftpd[(.*?)]/) {
  56. $found = 0;
  57. foreach $var(keys %pids){
  58. if(grep $1 =~ $var, keys %pids){
  59. $found = 1;
  60. }
  61. }
  62. if ($found == 0){
  63. push @{$pids{$1}}, $hhmm;
  64.  
  65. }
  66. }
  67. }
  68.  
  69. }
  70.  
  71. ##-------------------------------------------------------
  72. ## read each line from file into an array
  73. ##-------------------------------------------------------
  74. open (INPUT, $infile2) or die "Couldn't read $infile2.n";
  75.  
  76. my @messages;
  77.  
  78. while (my $line = <INPUT>){
  79. # if there is a match to the PID then put the line in the array
  80. if ($line =~ /ftpd[(.*?)]/){
  81. my $mPID = $1;
  82. foreach my $key (keys %pids){
  83. if ($key =~ $mPID){
  84. push @messages, $line;
  85. }
  86. }
  87. }
  88. }
  89.  
  90. # -------------------------------------------------------
  91. #find flow based on PID that was found from criteria
  92. #-------------------------------------------------------
  93.  
  94. foreach my $line(@messages){
  95. if(my($pid) = $line =~ m{ [ s*(d+) ]: }x) {
  96. if($line =~ /(d{2}):(d)/){
  97. my $time = $1 . ":" . $2;
  98. if ($pids{$pid}[0] =~ /$time/){
  99. push $pids{$pid}[0], $line;
  100. }
  101. }
  102. }
  103. }
  104.  
  105. $VAR1 = {
  106. '743' => {
  107. '' => '00:1'
  108. },
  109. '20687' => {
  110. '' => '01:3'
  111. },
  112.  
  113. $VAR1 = {
  114. '743' => '00:1',
  115. '20687' => '01:3',
  116. };
  117.  
  118. if($pids{$pid} == qr/$time/){
  119. $pids{$pid}{$time}[$y] = $line;
  120. $y++;
  121. };
  122.  
  123. $VAR1 = {
  124. '743' => '00:1',
  125. '4771' => {
  126. '23:5' => [
  127. 'Dec 1 23:59:23 ftp1 ftpd[4771]: USER test
  128. ',
  129. 'Dec 1 23:59:23 ftp1 ftpd[4771]: PASS password
  130. ',
  131. 'Dec 1 23:59:23 ftp1 ftpd[4771]: FTP LOGIN FROM 192.168.0.2 [192.168.0.2], test
  132. ',
  133. 'Dec 1 23:59:23 ftp1 ftpd[4771]: CWD /home/test/
  134. ',
  135. 'Dec 1 23:59:23 ftp1 ftpd[4771]: TYPE Image
  136. ',
  137. 'Dec 1 23:59:23 ftp1 ftpd[4771]: PASV
  138. ',
  139. 'Dec 1 23:59:23 ftp1 ftpd[4771]: RETR test
  140. ',
  141. 'Dec 1 23:59:23 ftp1 ftpd[4771]: QUIT
  142. ',
  143. 'Dec 1 23:59:23 ftp1 ftpd[4771]: FTP session closed
  144. '
  145. ]
  146. },
  147.  
  148. if($line =~ /(d{2}):(d)/ ) {
  149.  
  150. if($line =~ /(d{2}):(d{2})/ ) {
  151.  
  152. if ($line =~ /ftpd[(.*?)]/) {
  153. $pid{$1}[0] = $hhmm unless exists $pid{$1};
  154. }
  155.  
  156. if(grep $1 =~ $var, keys %pids){
  157.  
  158. my $pid = $1;
  159. if ($line =~ /ftpd[(.*?)]/) {
  160. $pid{$pid}{time} = $hhmm unless exists $pid{$pid};
  161. }
  162. if ($line =~ /USER (w+)/) {
  163. $pid{$pid}{user} = $1;
  164. }
  165.  
  166. $time{$hhmm}{pid} = $pid;
  167.  
  168. push @{$user{$1}}, $pid;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement