Shell Scripting - File Encrypter/Decrypter

HackerSploit · Intermediate ·📰 AI News & Updates ·7y ago

Key Takeaways

This video demonstrates how to create a shell script for file encryption and decryption using GPG, incorporating a menu for user choice and conditional statements for encryption and decryption options.

Full Transcript

[Laughter] [Music] hey guys hackersploit here back again with another video and welcome back to the shell scripting series i know i haven't made a video in this series for a while but uh it's time to make ground in this series and uh in this video we're going to be looking at how to create a simple file encrypter and decrypter uh obviously using the shell scripting uh now before i move on i just want to say something really really quickly i know i don't want to take your time if if if it seems that i don't reply to your comments or your questions it really is not because i don't want to it's because there are a lot of comments that i have to go through and usually i take about i would say about half an hour each day to reply to as many as i can so if i don't reply to yours immediately don't worry just know i will reply to it so for those of you asking uh you know why your comments are not being answered they just it's really a long list of comments that comes all in once and then i have to make time for that and then answer the question so uh please do bear with me if i don't answer it i'll probably answer it within 24 to 48 hours otherwise let's get started with this video so uh we are going to be creating a simple file encrypter slash decrypter it can do one or both of these functions one yeah one or both and uh will be so far using everything that we've learned uh all that we've learned will be involved here however i do want to tell you guys that if you feel that you can improve the script then by all means go ahead and do that i want to see you guys improve these scripts you know and see where we can go with them but the scripts are available on my github repository so again the link will be in the description so you can check out and we've made a lot of changes to the other scripts and they've really become better all right so we are going to be using uh we're going to be using a tool that is pre-installed on kali linux you might not have it on ubuntu but it's really very simple to install uh we're going to be using gpg which is essentially the gnu privacy guard as you probably would have known it uh it is it is like a frame implementation of open pgp and it allows you to encrypt data uh and also allows you to generate keys etc all right so i think i've made a few videos about it about uh gpg and that type of encryption but we're going to be using this and don't worry i'll be talking to you to you about the commands that you can use but the usage is is fairly simple in our case uh it's all about structuring the uh the code to make sense of it all right so let's get started i've created a file called encrypt dot shell you know really simple i have my shebang and we're ready to go all right so the first thing i'm going to say is i'm just going to display some text to the user and i'm going to say let me just increase the size of the terminal here so you guys can see what's going on so i'm going to say echo this is a simple file encrypter oops um encrypter uh decrypter you know it does both whatever you want it to do so we're just gonna say that uh and then we can say echo uh please um please choose what you want to do you know you can say something really simple like that essentially just telling them to make a choice we are going to use a menu now so again we'll create a list of choices so we're just going to call the list choice and the the list will be called um we'll say encrypt and decrypt so we looked at menus in the previous video and this is going to uh also incorporate that as you can see all right so that's the list so the choice is going to involve in encrypt or decrypt a file okay uh now um we can obviously start using the select which i'll do right now select uh so say select option that is the variable here so select option in choice which which will work so for so we can just select option in choice because that is exactly what we want we want to select an option in the choice the option is going to be that option one or option two of course the reply is different so select option in choice and we're gonna say do the following all right so we're then gonna use an if statement or a conditional statement whatever you wanna call it and as i mentioned in the previous video this is a perfect implementation of what can be done uh with menus and obviously furthermore with conditional statements all right so i'm going to say if and we're just going to follow the appropriate syntax so we're not going to say if the variable reply which stores the the reply uh that you enter or the use enter so if reply is equal to the value uh which is either option one or option two so we're gonna say in this case if it is equal to encrypt or option one i want you to do the following all right so i'm going to say uh we have obviously selected the uh the select and now we're using a conditional statement so we'll say now after the um after the conditional statement we're going to say the following uh so we'll say do the for i mean sorry we're just going to say then sorry about that i just really wanted to explain the structure so then this is in case of encrypting the file so we can say now uh you have selected selected uh and encrypt encryption you know something just vague like that of course you can customize it to whatever you want so you're going to say please enter the uh the file name now one problem with the script or one thing that i want you guys to fix as i mentioned with as i covered in the test in the tests video is i want you to to give the script functionality where you are able to select a directory the directory of the file that you want to encrypt in this case the script has to be run in the same directory of the of the file that you want to encrypt or decrypt all right so we're going to say please enter the file name and of course you have to specify the extension so pretty basic there uh so please uh enter the file and now we're going to read and we're going to store the data that we read uh which is essentially going to be the file name and the extension so we're going to say i knew there was a spelling mistake there so gonna say read and we'll give it a variable of file we'll just call it file and we now want to use the gpg command or the new privacy guard tool to essentially encrypt the file and the syntax is very simple so it's gpc gpg and we want to encrypt so we use the c command and then we specify the the name of the file which is stored in the file variable so file and that should be done so that will encrypt the file and if you can also incorporate the functionality of removing the original file which you can do which uh is possible by you know using remove remove r and then specify the file which will remove the original which i don't recommend unless you want to do it so you can customize that to your liking uh so we can say echo the file has uh has been encrypted like so encrypted and that should be that statement in in one area or one denomination of the conditional statement we then have the else you can use else if you want to if you want to specify additional parameters that judge the uh what the user enters in terms of the reply or the option in my case i'm just going to keep it simple so we're going to say else and we'll say echo this is now in terms of decryption so please and enter the um we can just say please enter the file name name and this is in case of decryption so let's also involve uh include the entrance statements that will be displayed to the user so you have selected a decryption uh like so and that should be good there all right so you have selected a decryption please enter the file name and now uh we again we're going to say we want to read and we'll give it a different variable name so we're going to say file and we can just say file two you know just store it under different variable and now we're going to use gpg again and jpg we now to decrypt a file you use the decrypt command and then you specify the variable that contains the file name and the extension which is file2 right and that should decrypt the file and again if you want to get rid of the original encrypted file you can go ahead and do that if you want to uh now gpgo automatically stores before i actually move on gpg automatically stores any passphrase that you use um in a list of keys that it has so if you're running this on a different system it's very important that you remember the pass phrase and i'll explain this as we move along okay so we can then run another another echo here saying echo uh the file has been uh decrypted all right and uh like so and we hit and we are done with that conditional statement so we can say fi to close the if statement and i think we are ready to to actually close uh these uh the menus also done and yeah so let's run this script so i'm going to save that and i'm going to exit and we're going to run the encrypt script now i'm in my i'm in the shell scripts folder which contains some of the scripts that we've been working on in previous videos so i'm what i'm going to do is i'm going to encrypt uh i'm going to encrypt the password generator dot shell file okay so let me run the encrypt shell over here and i'm going to hit enter and as you can see it's going to tell you this is a simple file encrypted decrypter please choose what you want to do so you can either choose to encrypt or decrypt a file so in my case i'm going to select option one i will encrypt a file and then we'll decrypt it all right so i'm going to say hit enter you have selected encryption please enter the file name the file name is we are currently in the working directory so i'm going to say uh let's encrypt uh password generator so you want to specify the file name password uh generator dot shell file uh and as i mentioned the this script has to be run within the same directory of the files that you want to encrypt or decrypt that's something that i want you guys to tweak and make better in the script all right so where you can specify uh the file directory all right so password generator dot shelf i'm gonna hit enter it's gonna prompt me to enter my passphrase for the encrypted file i'm gonna just type in password i'm gonna hit enter it's gonna tell me to re-enter the passphrase i'm gonna hit password and we should be good the file as it has encrypted and uh the script is still running which is really not what we want but i'll be covering that in the next video when you talk about exit exit codes and essentially essentially termination all right based on results so for now i'll just use control plus z to stop that completely uh and um if you if we list the files in here you can see that we have the uh the encrypted file password generator dot gpg right over here now of course you can specify the name of the file that you want to uh you you want you can specify the uh what's the correct word for it uh the name or the the new name of the encrypted file if you want to do that that's really very simple i'll again i think i can i'll be able to show you that in the next video when we'll be making a much better script all right so now we want to decrypt the file and as i mentioned uh if you're working on the same computer uh gpg stores uh the keys for you so you don't have to constantly keep typing them in as long as you're logged in as the user now of course if you run if you are to try and decrypt this file using the decrypter uh on on another computer then you need to know the passphrase in our case the password is very simple passphrase is uh password all right so i'm going to run the encrypt script again and we're going to hit enter and it's going to ask me what i want to do i'm going to say i want to decrypt the files when it enter you have selected decryption so please specify or enter the file name and we're just going to copy that just to save time as there is no auto completion i'm going to hit enter it's going to say um let me just explain what happened the uh the encryption was aes 256 encrypted data as you can see encrypted with one passphrase and because it has my keys it's going to decrypt the file and uh it'll display the contents of the file for you in in this case we know this was the password generator and it's going to display the password generator script all right so that is how to essentially create a very very simple password encrypted decrypt and the purpose of this video is to show you uh the the versatility as i mentioned again with shell scripting now you can combine the different aspects of them to to give a user various options and to increase functionality really uh so yeah we have discussed a lot of things now and i think we're ready now to move on to creating as i mentioned our network scanning script so the first video in that will be next i've already completed it uh but now it's time to recreate it with you guys and once that is done uh i will have the code on github way again you guys can improve it if you so choose to that being said that is going to be it for this video guys thank you so much for watching my videos i really appreciate the support if you found value in this video please leave a like down below if you have any questions or suggestions let me know in the comments section on my social networks or on my website and i'll be seeing you in the next video peace [Music] you

Original Description

Hey guys! HackerSploit here back again with another video, in this series we will be looking at how to create shell scripts. A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages Github Repo: https://github.com/AlexisAhmed/Shell-Scripts ⭐Help Support HackerSploit by using the following links: 🔗 NordVPN: https://nordvpn.org/hacker Use the link above or the code below for 77% Off your order Promo Code: hacker Patreon: http://patreon.com/hackersploit I Hope you enjoy/enjoyed the video. If you have any questions or suggestions feel free to ask them in the comments section or on my social networks. 🔗 HackerSploit Website: https://hsploit.com/ 🔗 HackerSploit Android App: https://play.google.com/store/apps/details?id=com.hsploitnews.hsploit&hl=en 🔹 Support The Channel NordVPN Affiliate Link: https://nordvpn.org/hacker Patreon: http://patreon.com/hackersploit 🔹 Get Our Courses Get a special discount on our courses: The Complete Deep Web Course 2018: https://www.udemy.com/the-complete-deep-web-course-2017/?couponCode=DWCBP2017 🔹 SOCIAL NETWORKS - Connect With Us! ------------------------------- Facebook: https://www.facebook.com/HackerSploit/ Twitter: https://twitter.com/HackerSploit Patreon: http://patreon.com/hackersploit -------------------------------- Thanks for watching! Благодаря за гледането Kiitos katsomisesta 感谢您观看 Merci d'avoir regardé Grazie per la visione Gracias por ver شكرا للمشاهدة دیکھنے کے لیے شکریہ देखने के लिए धन्यवाद
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from HackerSploit · HackerSploit · 0 of 60

← Previous Next →
1 How To Install Kali Linux 2.0 On Virtual Box
How To Install Kali Linux 2.0 On Virtual Box
HackerSploit
2 100 Subscriber Q&A! - How I Learned Ethical Hacking
100 Subscriber Q&A! - How I Learned Ethical Hacking
HackerSploit
3 BlackArch Linux Review - Better Than Kali Linux?
BlackArch Linux Review - Better Than Kali Linux?
HackerSploit
4 How to Access the Deep Web Safely | Deep Web Starter Guide 1.0
How to Access the Deep Web Safely | Deep Web Starter Guide 1.0
HackerSploit
5 Wireshark Tutorial for Beginners - Installation
Wireshark Tutorial for Beginners - Installation
HackerSploit
6 Wireshark Tutorial for Beginners - Overview of the environment
Wireshark Tutorial for Beginners - Overview of the environment
HackerSploit
7 Wireshark Tutorial for Beginners - Capture options
Wireshark Tutorial for Beginners - Capture options
HackerSploit
8 Wireshark Tutorial for Beginners - Filters
Wireshark Tutorial for Beginners - Filters
HackerSploit
9 Complete Ethical Hacking Course - Become a Hacker Today - #1 Hacking Terminology
Complete Ethical Hacking Course - Become a Hacker Today - #1 Hacking Terminology
HackerSploit
10 Complete Ethical Hacking Course #2 - Installing Kali Linux
Complete Ethical Hacking Course #2 - Installing Kali Linux
HackerSploit
11 Parrot OS 3.5 Review | The Best Kali Linux Alternative
Parrot OS 3.5 Review | The Best Kali Linux Alternative
HackerSploit
12 Nmap Tutorial For Beginners - 1 - What is Nmap?
Nmap Tutorial For Beginners - 1 - What is Nmap?
HackerSploit
13 Katoolin | How To Install Pentesting Tools On Any Linux Distro
Katoolin | How To Install Pentesting Tools On Any Linux Distro
HackerSploit
14 Nmap Tutorial For Beginners - 2 - Advanced Scanning
Nmap Tutorial For Beginners - 2 - Advanced Scanning
HackerSploit
15 Nmap Tutorial For Beginners - 3 - Aggressive Scanning
Nmap Tutorial For Beginners - 3 - Aggressive Scanning
HackerSploit
16 Zenmap Tutorial For Beginners
Zenmap Tutorial For Beginners
HackerSploit
17 How To Setup Proxychains In Kali Linux - #1 - Stay Anonymous
How To Setup Proxychains In Kali Linux - #1 - Stay Anonymous
HackerSploit
18 How To Setup Proxychains In Kali Linux - #2 - Change Your IP
How To Setup Proxychains In Kali Linux - #2 - Change Your IP
HackerSploit
19 How To Change Mac Address In Kali Linux | Macchanger
How To Change Mac Address In Kali Linux | Macchanger
HackerSploit
20 How To Setup And Use anonsurf On Kali Linux | Stay Anonymous
How To Setup And Use anonsurf On Kali Linux | Stay Anonymous
HackerSploit
21 Ubuntu 17.04 "Zesty Zapus" Review - Bye Unity
Ubuntu 17.04 "Zesty Zapus" Review - Bye Unity
HackerSploit
22 VPN And DNS For Beginners | Kali Linux
VPN And DNS For Beginners | Kali Linux
HackerSploit
23 Tails OS Installation And Review - Access The Deep Web/Dark Net
Tails OS Installation And Review - Access The Deep Web/Dark Net
HackerSploit
24 Steganography Tutorial - Hide Messages In Images
Steganography Tutorial - Hide Messages In Images
HackerSploit
25 The Lazy Script - Kali Linux 2017.1 - Automate Penetration Testing!
The Lazy Script - Kali Linux 2017.1 - Automate Penetration Testing!
HackerSploit
26 Best Linux Distributions For Penetration Testing
Best Linux Distributions For Penetration Testing
HackerSploit
27 Netcat Tutorial - The Swiss Army Knife Of Networking - Reverse Shell
Netcat Tutorial - The Swiss Army Knife Of Networking - Reverse Shell
HackerSploit
28 Gaining Access - Web Server Hacking - Metasploitable - #1
Gaining Access - Web Server Hacking - Metasploitable - #1
HackerSploit
29 Web Server Hacking - FTP Backdoor Command Execution With Metasploit - #2
Web Server Hacking - FTP Backdoor Command Execution With Metasploit - #2
HackerSploit
30 How To Install Kali Linux On VMware  - Complete Guide 2018
How To Install Kali Linux On VMware - Complete Guide 2018
HackerSploit
31 Q&A #1 - Best Cyber-security Certifications?
Q&A #1 - Best Cyber-security Certifications?
HackerSploit
32 Terminator - Kali Linux - Multiple Terminals
Terminator - Kali Linux - Multiple Terminals
HackerSploit
33 Shodan Search Engine Tutorial - Access Routers,Servers,Webcams + Install CLI
Shodan Search Engine Tutorial - Access Routers,Servers,Webcams + Install CLI
HackerSploit
34 Q&A #2 - Mr Robot?
Q&A #2 - Mr Robot?
HackerSploit
35 Metasploit Community Web GUI  - Installation And Overview
Metasploit Community Web GUI - Installation And Overview
HackerSploit
36 Linux Expl0rer - Forensics Toolbox - Installation & Configuration
Linux Expl0rer - Forensics Toolbox - Installation & Configuration
HackerSploit
37 QuasarRAT - The Best Windows RAT? - Remote Administration Tool for Windows
QuasarRAT - The Best Windows RAT? - Remote Administration Tool for Windows
HackerSploit
38 Metasploit For Beginners - #1 - The Basics - Modules, Exploits & Payloads
Metasploit For Beginners - #1 - The Basics - Modules, Exploits & Payloads
HackerSploit
39 Metasploit For Beginners - #2 - Understanding Metasploit Modules
Metasploit For Beginners - #2 - Understanding Metasploit Modules
HackerSploit
40 Kali Linux Quick Tips - #1 - Adding a non-root user
Kali Linux Quick Tips - #1 - Adding a non-root user
HackerSploit
41 Metasploit For Beginners - #3 - Information Gathering - Auxiliary Scanners
Metasploit For Beginners - #3 - Information Gathering - Auxiliary Scanners
HackerSploit
42 Spectre Meltdown Vulnerability  - How To Check Your System
Spectre Meltdown Vulnerability - How To Check Your System
HackerSploit
43 Metasploit For Beginners - #4 - Basic Exploitation
Metasploit For Beginners - #4 - Basic Exploitation
HackerSploit
44 ARP Spoofing With arpspoof - MITM
ARP Spoofing With arpspoof - MITM
HackerSploit
45 WordPress Vulnerability Scanning With WPScan
WordPress Vulnerability Scanning With WPScan
HackerSploit
46 Generating A PHP Backdoor with weevely
Generating A PHP Backdoor with weevely
HackerSploit
47 Nikto Web Vulnerability Scanner - Web Penetration Testing - #1
Nikto Web Vulnerability Scanner - Web Penetration Testing - #1
HackerSploit
48 How To Install Kali Linux On Windows 10 - Windows Subsystem For Linux
How To Install Kali Linux On Windows 10 - Windows Subsystem For Linux
HackerSploit
49 Stacer - System Optimizer And Monitoring Tool For Linux
Stacer - System Optimizer And Monitoring Tool For Linux
HackerSploit
50 Kali Linux 2018.1 - Kernel Updates & Patches
Kali Linux 2018.1 - Kernel Updates & Patches
HackerSploit
51 MITM With Ettercap - ARP Poisoning
MITM With Ettercap - ARP Poisoning
HackerSploit
52 Password Cracking With John The Ripper - RAR/ZIP & Linux Passwords
Password Cracking With John The Ripper - RAR/ZIP & Linux Passwords
HackerSploit
53 How To Detect Rootkits On Kali Linux - chkrootkit & rkhunter
How To Detect Rootkits On Kali Linux - chkrootkit & rkhunter
HackerSploit
54 Channel Updates - How To Post Questions & Video Suggestions
Channel Updates - How To Post Questions & Video Suggestions
HackerSploit
55 Web App Penetration Testing - #1 - Setting Up Burp Suite
Web App Penetration Testing - #1 - Setting Up Burp Suite
HackerSploit
56 Web App Penetration Testing - #2 - Spidering & DVWA
Web App Penetration Testing - #2 - Spidering & DVWA
HackerSploit
57 Cl0neMast3r - GitHub Repository Cloning Tool
Cl0neMast3r - GitHub Repository Cloning Tool
HackerSploit
58 Kali Linux On Windows 10 Official - WSL - Installation & Configuration
Kali Linux On Windows 10 Official - WSL - Installation & Configuration
HackerSploit
59 DoS/DDoS Protection - How To Enable ICMP, UDP & TCP Flood Filtering
DoS/DDoS Protection - How To Enable ICMP, UDP & TCP Flood Filtering
HackerSploit
60 Web App Penetration Testing - #3 - Brute Force With Burp Suite
Web App Penetration Testing - #3 - Brute Force With Burp Suite
HackerSploit

This video teaches how to create a shell script for file encryption and decryption using GPG, incorporating a menu for user choice and conditional statements for encryption and decryption options. The script uses AES 256 encryption and requires a passphrase or password for decryption.

Key Takeaways
  1. Display text to the user
  2. Create a menu for user choice
  3. Use select command to choose an option in the menu
  4. Select user input for encryption or decryption option
  5. Use if statement to check user input and perform corresponding action
  6. Use gpg command to encrypt file
  7. Remove original file after encryption
  8. Use echo to display messages to user
  9. Run the encrypt script
  10. Select decryption option
💡 The use of GPG for encryption and decryption provides a secure way to protect files, and the incorporation of a menu and conditional statements makes the script user-friendly and flexible.

Related AI Lessons

Up next
‘ENOUGH IS ENOUGH’: Lebanon is STANDING UP to Iran, expert says
Fox Business
Watch →