Advertisement
xGHOSTSECx

ScriptKiddieCowboys.sh

Dec 25th, 2023
1,073
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 12.07 KB | None | 1 0
  1. #!/bin/bash
  2.  
  3. # The Comprehensive Educational Guide and Research Project in Bash Scripting
  4. # By Michael Errington
  5.  
  6. # Function to check internet connectivity
  7. check_internet() {
  8.     ping -c 1 google.com &> /dev/null
  9.     if [ $? -eq 0 ]; then
  10.         echo "Internet connection is active."
  11.     else
  12.         echo "No internet connection."
  13.     fi
  14. }
  15.  
  16. # Function to display basic system information
  17. system_info() {
  18.     echo "System Information:"
  19.     uname -a
  20.     echo "Available Disk Space:"
  21.     df -h
  22. }
  23.  
  24. # Function to create a new directory
  25. create_directory() {
  26.     local directory_name="$1"
  27.    
  28.     # Create a new directory
  29.     mkdir "$directory_name"
  30.    
  31.     echo "Directory '$directory_name' created."
  32. }
  33.  
  34. # Function to search for a file
  35. search_file() {
  36.     local file_name="$1"
  37.    
  38.     # Search for the file in the home directory
  39.     find ~/ -name "$file_name"
  40.    
  41.     echo "File search complete."
  42. }
  43.  
  44. # Function to connect to a website using curl
  45. connect_to_website() {
  46.     local website_url="$1"
  47.     local curl_output
  48.  
  49.     # Use curl to connect to the website and save the content to a variable
  50.     curl_output=$(curl -s "$website_url")
  51.  
  52.     # Check if curl was successful (HTTP status code 200)
  53.     if [ $? -eq 0 ]; then
  54.         echo "Curl connection successful."
  55.         return 0  # Success
  56.     else
  57.         echo "Curl connection failed."
  58.         return 1  # Failure
  59.     fi
  60. }
  61.  
  62. # Function to download a resource using wget
  63. download_resource() {
  64.     local resource_url="$1"
  65.    
  66.     # Use wget to download the resource to a specified directory
  67.     wget -P ./downloads/ "$resource_url"
  68.    
  69.     # Check if wget was successful
  70.     if [ $? -eq 0 ]; then
  71.         echo "Wget download successful."
  72.         return 0  # Success
  73.     else
  74.         echo "Wget download failed."
  75.         return 1  # Failure
  76.     fi
  77. }
  78.  
  79. # Function to parse HTML content and extract specific information
  80. parse_html() {
  81.     local html_content="$1"
  82.    
  83.     # Use grep or other tools to extract relevant information from HTML
  84.     # Example: Extracting all links from HTML
  85.     links=$(echo "$html_content" | grep -o '<a [^>]\+>' | grep -o 'href="[^\"]\+"' | sed 's/href="//;s/"//')
  86.    
  87.     echo "Extracted links: $links"
  88. }
  89.  
  90. # Function to clean up temporary files
  91. cleanup() {
  92.     local temp_file="$1"
  93.    
  94.     # Remove the temporary file
  95.     rm "$temp_file"
  96. }
  97.  
  98. # Function to interact with a REST API using cURL
  99. rest_api_interaction() {
  100.     local api_url="$1"
  101.    
  102.     # Use cURL to make a GET request to the API
  103.     api_response=$(curl -s "$api_url")
  104.    
  105.     echo "API Response:"
  106.     echo "$api_response"
  107. }
  108.  
  109. # Function to list contents of a directory
  110. list_directory() {
  111.     local directory="$1"
  112.    
  113.     # List contents of the specified directory
  114.     ls -l "$directory"
  115.    
  116.     echo "Directory listing complete."
  117. }
  118.  
  119. # Function to create and edit a text file
  120. create_and_edit_file() {
  121.     local file_name="$1"
  122.    
  123.     # Create a new text file and open it in a text editor
  124.     touch "$file_name" && nano "$file_name"
  125.    
  126.     echo "Text file '$file_name' created and edited."
  127. }
  128.  
  129. # Function to count the number of lines in a file
  130. count_lines() {
  131.     local file_name="$1"
  132.    
  133.     # Use wc to count the number of lines in the file
  134.     lines=$(wc -l < "$file_name")
  135.    
  136.     echo "Number of lines in '$file_name': $lines"
  137. }
  138.  
  139. # Function to rename a file
  140. rename_file() {
  141.     local old_name="$1"
  142.     local new_name="$2"
  143.    
  144.     # Rename the file
  145.     mv "$old_name" "$new_name"
  146.    
  147.     echo "File '$old_name' renamed to '$new_name'"
  148. }
  149.  
  150. # Function to create a compressed archive of files
  151. create_archive() {
  152.     local archive_name="$1"
  153.     local files_to_archive="$2"
  154.    
  155.     # Create a compressed archive of specified files
  156.     tar -czf "$archive_name" $files_to_archive
  157.    
  158.     echo "Archive '$archive_name' created."
  159. }
  160.  
  161. # Function to display the current date and time
  162. display_date_time() {
  163.     date
  164. }
  165.  
  166. # Function to self-destruct the script
  167. self_destruct() {
  168.     echo "Initiating self-destruct sequence..."
  169.     rm -- "$0"
  170.     echo "Self-destruct complete. Script terminated."
  171.     exit 0
  172. }
  173.  
  174. # Beginner Functions:
  175.  
  176. # Function to check available disk space
  177. check_disk_space() {
  178.     echo "Available Disk Space:"
  179.     df -h
  180.     echo "Disk space check complete."
  181. }
  182.  
  183. # Function to list all installed packages
  184. list_installed_packages() {
  185.     echo "Installed Packages:"
  186.     dpkg --list
  187.     echo "Package listing complete."
  188. }
  189.  
  190. # Function to display running processes
  191. list_processes() {
  192.     echo "Running Processes:"
  193.     ps aux
  194.     echo "Process listing complete."
  195. }
  196.  
  197. # Function to create a backup of a file
  198. create_backup() {
  199.     local file_name="$1"
  200.     local backup_name="$file_name.backup"
  201.  
  202.     # Copy the file to create a backup
  203.     cp "$file_name" "$backup_name"
  204.  
  205.     echo "Backup created: $backup_name"
  206. }
  207.  
  208. # Function to display system uptime
  209. display_uptime() {
  210.     echo "System Uptime:"
  211.     uptime
  212.     echo "Uptime information complete."
  213. }
  214.  
  215. # Function to list available network interfaces
  216. list_network_interfaces() {
  217.     echo "Available Network Interfaces:"
  218.     ifconfig -a
  219.     echo "Network interfaces listing complete."
  220. }
  221.  
  222. # Function to display file permissions
  223. display_file_permissions() {
  224.     local file_name="$1"
  225.    
  226.     # Display permissions of the specified file
  227.     ls -l "$file_name" | awk '{print $1}'
  228.    
  229.     echo "File permissions displayed."
  230. }
  231.  
  232. # Function to extract a tar archive
  233. extract_archive() {
  234.     local archive_name="$1"
  235.    
  236.     # Extract contents of the specified archive
  237.     tar -xzf "$archive_name" -C ./extracted_contents
  238.    
  239.     echo "Archive '$archive_name' extracted."
  240. }
  241.  
  242. # Function to check system memory usage
  243. check_memory_usage() {
  244.     echo "System Memory Usage:"
  245.     free -h
  246.     echo "Memory usage check complete."
  247. }
  248.  
  249. # Advanced Functions:
  250.  
  251. # Function to analyze network connections
  252. analyze_network_connections() {
  253.     echo "Network Connections Analysis:"
  254.     netstat -tunap
  255.     echo "Network connections analysis complete."
  256. }
  257.  
  258. # Function to monitor system resource usage continuously
  259. monitor_resources_continuous() {
  260.     echo "Monitoring system resource usage continuously. Press Ctrl+C to stop."
  261.     top
  262. }
  263.  
  264. # Function to find and kill a specific process
  265. kill_process() {
  266.     local process_name="$1"
  267.  
  268.     # Find the process ID (PID) using grep and awk
  269.     local process_pid=$(ps aux | grep "$process_name" | awk '{print $2}')
  270.  
  271.     # Kill the process
  272.     kill -9 "$process_pid"
  273.  
  274.     echo "Process '$process_name' (PID: $process_pid) killed."
  275. }
  276.  
  277. # Function to analyze system logs
  278.     analyze_system_logs() {
  279.     echo "System Logs Analysis:"
  280.     tail /var/log/syslog
  281.     echo "System logs analysis complete."
  282. }
  283.  
  284. # Function to create a symbolic link
  285. create_symbolic_link() {
  286.     local target_file="$1"
  287.     local link_name="$2"
  288.  
  289.     # Create a symbolic link
  290.     ln -s "$target_file" "$link_name"
  291.  
  292.     echo "Symbolic link created: $link_name -> $target_file"
  293. }
  294.  
  295. # Research Project: Advanced Bash Scripting for Cybersecurity
  296.  
  297. echo "Welcome to the research project section, where we explore advanced Bash scripting in the realm of cybersecurity. I'm Michael Errington, and together, we'll delve into powerful scripting techniques."
  298.  
  299. # Function to analyze system users
  300. analyze_system_users() {
  301.     echo "System Users Analysis:"
  302.     cut -d: -f1 /etc/passwd
  303.     echo "System users analysis complete."
  304. }
  305.  
  306. # Function to display firewall rules
  307. display_firewall_rules() {
  308.     echo "Firewall Rules:"
  309.     iptables -L
  310.     echo "Firewall rules display complete."
  311. }
  312.  
  313. # Function to check open ports
  314. check_open_ports() {
  315.     echo "Open Ports Check:"
  316.     ss -tunl
  317.     echo "Open ports check complete."
  318. }
  319.  
  320. # Function to perform a security audit
  321. security_audit() {
  322.     echo "Security Audit:"
  323.     Lynis
  324.     echo "Security audit complete."
  325. }
  326.  
  327. # Function to scan for open vulnerabilities
  328. scan_for_vulnerabilities() {
  329.     echo "Vulnerability Scanning:"
  330.     OpenVAS
  331.     echo "Vulnerability scanning complete."
  332. }
  333.  
  334. # Function to encrypt a file
  335. encrypt_file() {
  336.     local file_name="$1"
  337.    
  338.     # Use GPG to encrypt the file
  339.     gpg -c "$file_name"
  340.    
  341.     echo "File '$file_name' encrypted."
  342. }
  343.  
  344. # Function to decrypt a file
  345. decrypt_file() {
  346.     local encrypted_file="$1"
  347.    
  348.     # Use GPG to decrypt the file
  349.     gpg -d "$encrypted_file" > "${encrypted_file%.gpg}"
  350.    
  351.     echo "File '$encrypted_file' decrypted."
  352. }
  353.  
  354. # Educational Additions:
  355.  
  356. echo "Let's expand our knowledge with additional educational functions."
  357.  
  358. # Function to display kernel information
  359. display_kernel_info() {
  360.     echo "Kernel Information:"
  361.     uname -r
  362.     echo "Kernel information displayed."
  363. }
  364.  
  365. # Function to analyze disk usage
  366. analyze_disk_usage() {
  367.     echo "Disk Usage Analysis:"
  368.     du -h --max-depth=1 /
  369.     echo "Disk usage analysis complete."
  370. }
  371.  
  372. # Function to display active SSH sessions
  373. display_active_ssh_sessions() {
  374.     echo "Active SSH Sessions:"
  375.     who
  376.     echo "Active SSH sessions displayed."
  377. }
  378.  
  379. # Function to display system temperature
  380. display_system_temperature() {
  381.     echo "System Temperature:"
  382.     sensors
  383.     echo "System temperature displayed."
  384. }
  385.  
  386. # Function to check for available software updates
  387. check_software_updates() {
  388.     echo "Available Software Updates:"
  389.     sudo apt list --upgradable
  390.     echo "Software updates check complete."
  391. }
  392.  
  393. # Beginner Functions (Additional):
  394.  
  395. # Function to list USB devices
  396. list_usb_devices() {
  397.     echo "List of USB Devices:"
  398.     lsusb
  399.     echo "USB device listing complete."
  400. }
  401.  
  402. # Function to display system information using uname
  403. display_system_info_uname() {
  404.     echo "System Information (uname):"
  405.     uname -a
  406.     echo "System information displayed using uname."
  407. }
  408.  
  409. # Function to create a text file and add content
  410. create_and_add_content() {
  411.     local file_name="$1"
  412.     local content="$2"
  413.  
  414.     # Create a new text file and add content
  415.     echo "$content" > "$file_name"
  416.  
  417.     echo "Text file '$file_name' created and content added."
  418. }
  419.  
  420. # Function to display system information using hostnamectl
  421. display_system_info_hostnamectl() {
  422.     echo "System Information (hostnamectl):"
  423.     hostnamectl
  424.     echo "System information displayed using hostnamectl."
  425. }
  426.  
  427. # Function to display environment variables
  428. display_environment_variables() {
  429.     echo "Environment Variables:"
  430.     printenv
  431.     echo "Environment variables displayed."
  432. }
  433.  
  434. # Advanced Functions (Additional):
  435.  
  436. # Function to check for rootkits
  437. check_for_rootkits() {
  438.     echo "Checking for Rootkits:"
  439.     rkhunter --check
  440.     echo "Rootkit check complete."
  441. }
  442.  
  443. # Function to perform a port scan
  444. perform_port_scan() {
  445.     local target_ip="$1"
  446.  
  447.     echo "Performing Port Scan on $target_ip:"
  448.     nmap "$target_ip"
  449.     echo "Port scan complete."
  450. }
  451.  
  452. # Function to analyze network traffic
  453. analyze_network_traffic() {
  454.     echo "Network Traffic Analysis:"
  455.     tcpdump -i any
  456.     echo "Network traffic analysis complete. Press Ctrl+C to stop."
  457. }
  458.  
  459. # Function to check for listening services
  460. check_listening_services() {
  461.     echo "Checking for Listening Services:"
  462.     netstat -tulpn
  463.     echo "Listening services check complete."
  464. }
  465.  
  466. # Function to backup and compress a directory
  467. backup_and_compress_directory() {
  468.     local directory_path="$1"
  469.     local backup_name="backup_$(date +'%Y%m%d').tar.gz"
  470.  
  471.     # Create a compressed archive of the specified directory
  472.     tar -czf "$backup_name" "$directory_path"
  473.  
  474.     echo "Backup and compression of '$directory_path' complete. Archive: $backup_name"
  475. }
  476.  
  477. # Concluding Thoughts:
  478.  
  479. echo "Our journey concludes with a comprehensive understanding of Bash scripting, ranging from fundamental tasks to advanced cybersecurity applications. Remember, the power of scripting lies in automation, and as you continue your exploration, you'll discover endless possibilities."
  480.  
  481. echo "Thank you for joining me on this educational and research-driven adventure. Keep scripting, keep exploring, and may your cybersecurity endeavors be both exciting and impactful."
  482.  
  483. # Self-destruct the script
  484. self_destruct
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement