Shuraken007

overthewire_1_12

May 18th, 2023 (edited)
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.61 KB | None | 0 0
  1. # first of all I played with shh / scp / rsync commands
  2. # and created a bit ugly script on perl, which expands all crap,
  3. # I stored at structure things like
  4. #   host_name, user_id, password or file with password
  5. #   port, e.t.c.
  6. #
  7. # so, it's easy to login and trassfer files now
  8. # if password exists, all commands gain prefix
  9. # sshpass -p bandit0 | sshpass -f ~/tmp/bash_game/../loaded_file
  10. # ssh user -> ssh user@server
  11. # scp user:path -> ssh user@server:path
  12. # scp user:'path with spaces' -> ssh user@server:"path\ with\ spaces"
  13. #
  14. # also port auto added if exists at config
  15. # scp user:smth -> scp -P 2220 user@server:smth
  16. # scp user -> scp user@path -p 2220
  17. # rsync -R user:smth -> rsyn -e 'ssh -p 2220' --info=progress2 -R user@....
  18. #
  19. # script on perl
  20. # https://pastebin.com/n7zPMMDq
  21. #
  22. # aliases for bash, which uses script
  23. # https://pastebin.com/ecaU6XCm
  24.  
  25. # 0->1
  26. cat readme
  27. # 1->2
  28. cat ./-
  29. # 2->3
  30. cat 'spaces in this filename'
  31. # 3->4
  32. cd inhere
  33. ll
  34. cat .hidden
  35. # 4->5
  36. cd inhere/
  37. find . -exec file "{}" \; | grep ASCII | grep -v Non;
  38. # 5->6
  39. find inhere/ -readable -and -size 1033c -and ! -executable | cat
  40.  
  41. # 6->7
  42. #1. using find options
  43. find / -user bandit7 -group bandit6 -size 33c 2>/dev/null
  44.  
  45. # 2. find used only to iterate file
  46. find inhere/ -type f | while read -r f; do ls -l "$f"; done | perl -awne 'print "$F[-1]\n" if ($F[0] !~ /x/ && $F[4]==1033)' | while read -r f; do file "$f"; done | grep 'ASCII text' | cut -d: -f1 | (x=$(cat);cat $x)
  47. # explanation
  48. #   a) ls prints giant table for each file
  49. #   b) data from std_in read via read -r line by line
  50. #   c) next perl oneliner works
  51. #   perl options -awne
  52. #   -e -- execute, perl -e 'some_code here' - common oneliner notation
  53. #   -w -- warnings, print warnings to debug code
  54. #   -n -  wrap code to cycle, default cycle variable $_ store line of input
  55. #     BEGIN {some code} # optional
  56. #     while (<>) {
  57. #       'my code here'
  58. #       print $_; # $_ contains result of read -r _
  59. #     }
  60. #     END {some code} # optional
  61. #   -a -- autosplit by ' ', each line splited and stored at array @F
  62. #     it's possible to user delim -F: - split via ':'
  63. # d) use comand file on each output file via read again
  64. # e) grep readable file
  65. # f) get only file name part
  66. # g) cat file, it's possible to get file_name with read -r, but I got with $(cat) for fun
  67. #     a=$() runs anonymous shell, executes what inside and put result to variable `a`
  68. #     cat by default reads std_in, but this time std_in is ouput from prev command
  69. # 3. same, but via xargs versus while ... done and $(cat)
  70. find inhere/ -type f | xargs -I {} ls -l "{}" | perl -awne 'print "$F[-1]\n" if ($F[0] !~ /x/ && $F[4]==1033)' | xargs -I {} file "{}" | grep 'ASCII text' | cut -d: -f1 | xargs cat
  71. # explanation
  72. # -I macro some_command arg1 "smth macro smth2" arg2..., so it's possible to use macro multiple times
  73. # {} - notation from file -exec, but it could be any
  74.  
  75. # 7-8
  76. grep millionth data.txt | cut -f2
  77. # 8->9
  78. # create struct for perl - hash a
  79. # a = (
  80. #   'first_str' = 3, # 3 times count
  81. #   'second_str' = 2,
  82. #   ...
  83. #   'last_str' = 8,
  84. # )
  85. cat data.txt | perl -ne 'BEGIN{%a=();}$a{$_}++;END{while(($k,$v) = each %a) {print $k if $v==1}}'
  86. # 9->10
  87. cat data.txt | perl -ne 'print "$&\n" if $_ =~ /={2,}\s+\K\w{5,}/'
  88. # want at least 2 '=' and at least 5 [a-zA-Z0-9], e.g. \w
  89. # \K removes all matched from group
  90. cat data.txt | grep -aPo '={2,}\s+\K(\w{5,})'
  91.   # -a for binary files
  92.   # -o - only matching strings
  93.   # -P - perl regexp engine
  94.  
  95. # 10->11
  96. base64 --decode data.txt
  97.  
  98. # 11->12
  99. cat data.txt | perl -pe 'tr/N-ZA-Mn-za-m/A-Za-z/'
  100. tr 'A-Za-z' 'N-ZA-Mn-za-m' < data.txt
Tags: bandit_games
Add Comment
Please, Sign In to add comment