diff --git a/Task2/anushka_c/Dockerfile b/Task2/anushka_c/Dockerfile new file mode 100644 index 0000000..11fdad3 --- /dev/null +++ b/Task2/anushka_c/Dockerfile @@ -0,0 +1,11 @@ +FROM gcc:latest + +WORKDIR /app + +COPY . . + +RUN g++ -std=c++17 -o netflix main.cpp + +CMD ["./netflix"] + +RUN make \ No newline at end of file diff --git a/Task2/anushka_c/Makefile b/Task2/anushka_c/Makefile new file mode 100644 index 0000000..099c6b9 --- /dev/null +++ b/Task2/anushka_c/Makefile @@ -0,0 +1,2 @@ +all: + g++ -std=c++17 -o netflix main.cpp diff --git a/Task2/anushka_c/main.cpp b/Task2/anushka_c/main.cpp new file mode 100644 index 0000000..8475b98 --- /dev/null +++ b/Task2/anushka_c/main.cpp @@ -0,0 +1,310 @@ +#include +#include +#include +#include +using namespace std; +//Base Content Class +class Content { +public : + string title; + string genre; + float rating; + bool is_rented = false; + bool is_purchased = false; + Content(string t, string g, float r) { //constuctor + title = t; + genre = g; + rating = r; + } + virtual void showInfo() = 0; + virtual float getRentCost() = 0; + virtual float getPurchaseCost() = 0; +}; +//Movie Class +class Movie : public Content { +public : + int duration; + float rentCost; + float purchaseCost; + Movie(string t, string g, float r, int d, float rC, float pC) + : Content(t, g, r) {//constructor1 + duration = d; + rentCost = rC; + purchaseCost = pC; + } + void showInfo() { + cout<<"Movie Name : "< rented; + vector purchased; + float charges = 0.0; + User(string name) { + userName = name; + } + void rentContent(Content* content) { + if(!content->is_rented) { + content->is_rented = true; + rented[content->title] = time(0); + charges = charges+content->getRentCost(); + cout<<"Rented successfully!\n"; + }else { + cout<<"Already rented.\n"; + } + } + void purchaseContent(Content* content) { + if(!content->is_purchased) { + content->is_purchased = true; + purchased.push_back(content->title); + charges = charges+content->getPurchaseCost(); + cout<<"Purchased successfully!\n"; + }else { + cout<<"Already purchased.\n"; + } + } + void returnContent(Content* content) { + if(content->is_rented) { + content->is_rented = false; + rented.erase(content->title); + cout<<"Returned successfully!\n"; + }else { + cout<<"Not rented.\n"; + } + } + void viewCurrStatus() { + cout<<"Username : "<< userName<<"\n"; + cout<<"Rented : \n"; + for(auto& r : rented) { + cout<& newAddition, Content* content) { + newAddition.push_back(content); + cout<<"New Content added!\n"; + } + void deleteContent(vector& newAddition, string t) { + for(auto i = newAddition.begin(); i!=newAddition.end(); i++) { + if((*i)->title == t) { + delete *i; + newAddition.erase(i); + cout<<"Content removed!\n"; + return; + } + } + cout<<"Content not found!\n"; + } + void checkCharges(User& user) { + cout< &List) { + cout<<"All available content\n"; + cout<<"Pre-added content : \n"; + cout<<"1. Marvel : Avengers\n"; + cout<<"Sci-fi\n"; + cout<<"8.9\n"; + cout<<"Not rented\n"; + cout<<"Not purchased\n"; + cout<<"2. The Conjuring\n"; + cout<<"Horror\n"; + cout<<"9.2\n"; + cout<<"Not rented\n"; + cout<<"Not purchased\n"; + + for(Content* c : List) { + c->showInfo(); + } +} +int main() { + vector allAdditions; + map users; + string str = "netflixAdmin"; + Admin admin(str); + while(1) { + cout<<"Press digit to perform the corresponding operation.\n"; + + cout<<"1. User Login\n"; + cout<<"2. User Signup\n"; + cout<<"3. Admin Login\n"; + cout<<"4. Exit\n"; + int choice; + cin>>choice; + if(choice == 4) { + break; + } + if(choice == 1 || choice == 2) { + string uName; + cout<<"Enter Username : "; + cin>>uName; + if(choice == 2) { + if(users.find(uName)!=users.end()) { + cout<<"Username taken.\n"; + continue; + }else { + users[uName] = new User(uName); + cout<<"User created!\n"; + } + } + if(!users.count(uName)) { + cout<<"No such user.\n"; + continue; + } + User* current = users[uName]; + while(1) { + cout<<"User Menu : \n"; + cout<<"Press digit key to perform corresponding operation.\n"; + cout<<"1. Browse\n2. Rent\n3. Return\n4. Purchase\n5. View Status\n"; + cout<<"6.Logout\n"; + int uChoice; + cin>>uChoice; + if(uChoice == 6) { + break; + } + if(uChoice == 1) { + showAllContent(allAdditions); + }else if(uChoice == 2 || uChoice == 3 || uChoice == 4) { + string title; + cout<<"Enter title : \n"; + cin.ignore(); + getline(cin, title); + bool found = false; + for(Content* c : allAdditions) { + if(c->title == title) { + if(uChoice == 2) { + current->rentContent(c); + }else if(uChoice == 3) { + current->returnContent(c); + }else if(uChoice == 4) { + current->purchaseContent(c); + } + found = true; + break; + } + } + if(!found) { + cout<<"Content not found\n"; + } + }else if(uChoice == 6) { + current->viewCurrStatus(); + } + + } + }else if(choice == 3) { + string passWord; + cout<<"Enter admin password : \n"; + cin>>passWord; + if(passWord!="defaultPass123") { + cout<<"Incorrect Password\n";//default password by system that admin must enter + continue; + } + while(1) { + cout<<"Admin Menu : \n"; + cout<<"Press digit key to perform corresponding operation\n"; + cout<<"1. Add content\n2. Remove Content\n3. Check User charges\n4. Logout\n"; + int aChoice; + cin>>aChoice; + if(aChoice == 4) { + break; + } + if(aChoice == 1) { + cout<<"1. Movie\n"<<"2. TV Show"; + int k; + cin>>k; + string title, genre; + float rating; + cin.ignore(); + cout<<"Title : "; + getline(cin, title); + cout<<"Genre : "; + getline(cin, genre); + cout<<"Rating : "; + cin>>rating; + if(k == 1) { + int dur; float r,p; + cout<<"Duration : "; cin>>dur; + cout<<"Rent Cost : "; cin>>r; + cout<<"Purchase Cost : "; cin>>p; + admin.addNewContent(allAdditions, new Movie(title, genre, rating, dur, r, p)); + }else { + int seasons, eps; float r, p; + cout<<"Seasons : "; cin>> seasons; + cout<<"Episodes/Season : "; cin>> eps; + cout<<"Rent/Season : "; cin>> r; + cout<<"Purchase/Season : "; cin>>p; + admin.addNewContent(allAdditions, new TVShow(title, genre, rating, seasons, eps, r, p)); + + } + }else if(aChoice == 2) { + string title; + cout<<"Enter title to remove : "; + cin.ignore(); + getline(cin, title); + admin.deleteContent(allAdditions, title); + }else if(aChoice == 3) { + string uname; + cout<<"Enter Username : "; + cin>>uname; + if(users.count(uname)) { + admin.checkCharges(*users[uname]); + }else { + cout<<"User Not found.\n"; + } + } + } + } + } + return 0; + +} diff --git a/otw.md b/otw.md new file mode 100644 index 0000000..5ebed22 --- /dev/null +++ b/otw.md @@ -0,0 +1,44 @@ +# Bandit wargames : +This games requires to find the passwords at each level, using different Linux commands. +Connection : We logged in into the game using ssh, which is secure shell.The host to which we need to connect is bandit.labs.overthewire.org, on port 2220.The username is bandit0 and the password is bandit0. Once logged in, we move to the zeroth level of the game. +## Level 0 : +In this level, in order to get the password for the next level, we need to find it in a readme file in home directory. I used ls to first list the file in home directory. Then I used cat to read the file. And hence, got password for the next level. +## Level 1 : +For moving to the next level, we need to find a file named - in home directory. In order to get the password, I used cat/- to open the file with this name. Hence, got the password. +## Level 2 : +For this level, password is in a file named "spaces in this filename". First, I use ls to list all the files. Then, I used cat and wrote the file name in inverted commas to open the file. Hence, I got the password and moved to the next level. +## Level 3 : +In this level, password is in a hidden file in inhere directory. To get this, first I did ls to list the files and folders. Then, cd inhere to open the folder. Then did ls -a to list all the hidden files. Then I got a file named "...hiding from you". Then used cat to open this file. Hence, I got the password. +## Level 4 : +In this level, password is again in inhere directory but it is an human readable file. I did ls to get the directory inhere. Then I navigated it using cd inhere. Then I used ls -l. +Then all the files in the directory showed up. Next command is file ./*, this gave the datatype that is stored in each file. For file 7, the datatype is different from all others. This file has password. Then used cat to open the file. Hence, got the password. +## Level 5 : +In this level, in inhere directory, there is a file which is human readable, 1033 byte sized and non executable. I did ls, then cd inhere. Then find . -type f -size 1033c ! executable to find the file with given requirements. This gives the file address. Then cat ./maybehere07/.file2 . Hence, got the password. +## Level 6 : +In this level, file address is unknown. The properties of the file are given. Then use command find / -user bandit7 -group bandit6 -size 33c -type f -print 2>/dev/null to find the file with given requirements. Then I got the file address and used cat to open it. Hence, got the password. +## Level 7 : +In this level, there is a file named data.txt in home directory . There is a line in this file which starts with millions, password is in that line. I used the following commands to get the password +cat data.txt | grep millionth +Hence, got the password. +## Level 8 : +In this level, in the file data.txt, every line is getting repeated except 1, which has the password. I used the following commands +sort data.txt | uniq -c | grep '^ *1 ' . Here, first I sorted all the lines in data.txt in alphabetical order, then the output of this goes as input to uniq -c. Then uniq command processes the sorted lines and outputs each unique line along with a count of how many times it appears. Then output of this goes to grep, and the following command matches the exponential sign to the beginning of the line, asterisk matches 0 or more spaces. 1 matches 1 followed by a space. This ensures we are only selecting lines that appear once. Hence, got the password and moved to the next level. +## Level 9 : +In this level, the file data.txt has only few human readable strings preceded by several = characters. The command I used here is cat data.txt | strings -e s | grep ==. Opened the file using cat, the output of this goes to strings command, the output of strings goes to grep which checks for = character in the output. It printed 4 lines, where 1 line contains the password. Hence, moved to the next level. +## Level 10 : +Tn this level, the password for the next level is stored in the file data.txt which contains base64 encoded data. The command used is base64 -d data.txt. This calls base64, -d is used to decode the file. This prints the password. +## Level 11 : +In this level, there is a data.txt file where all lowercase and uppercase letters have been rotated by 13 positions. The command used is cat data.txt | tr 'a-zA-Z' 'n-za-mN-ZA-M'. Here cat data.txt: reads the contents of the data.txt file and sends it to the standard output.Then, pipe sends the output of cat to the input of the tr command. +tr 'a-zA-Z' 'n-za-mN-ZA-M': This is the translation part. +'a-z': Represents all lowercase letters from 'a' to 'z'. These will be translated to the corresponding letters in the second set. +'A-Z': Represents all uppercase letters from 'A' to 'Z'. These will also be translated. +'n-za-m': This is the ROT13-shifted lowercase alphabet. 'a' becomes 'n', 'b' becomes 'o', ..., 'm' becomes 'z', and then it wraps around: 'n' becomes 'a', 'o' becomes 'b', ..., 'z' becomes 'm'. +'N-ZA-M': This is the ROT13-shifted uppercase alphabet, following the same logic as the lowercase. +This outputs the password. +## Level 12 : +In this level, the password is in data.txt file which is a hexdump of a file that has been repeatedly compressed. A temporary directory is to be made using command mkdir /tmp/folder/. Then cd tmp/folder/ to open the temporary directory. Then copied the data.txt file in home directory to current directory using cp ~/data.txt. Then used command xxd -r data.txt > data2.txt to convert ascii text to gunzip. Then renamed the file data2.txt to binary.gz. Then extracted the file the file using gunzip binary.gz. Then the output will be a file named binary. To check the filetype of this file, used the command file binary. This gives a file of filetype bzip2. Then extracted this using bunzip. The command is bzip2 binary. This outputs a file named binary.bz2. To check the filetype, used file binary.bz2. Then extracted this file using bzip2 -d binary. This gives an extracted file named binary.out. Then, checked its filetype which is gunzip. Then renamed binary.out to binary.hz using mv binary.out binary.gz. Then extracted from gunzip using gunzip binary.gz. Similarly, extracted it multiple times. Finally got a file with datatype asciitext named data8. Then opened it using cat and got the password. +## Level 13 : +In this level, the password for next level is stored in /etc/bandit_pass/bandit14 and only bandit14 user can read it. This will not give a password but will give an ssh key. Listed the files using ls, got a file named sshkey.private. ssh command can be used with the -i flag to use the private key. Then used the command ssh -i sshkey.private -key 2220. I have logged as bandit14 user. To get the password for the current user, command used cat /etc /bandit_pass/bandit14. This gives the password for 14 level. +## Level 14 : +In this level, the password for the next level can be retrived by submitting the password of the current level to port 30000 on localhost. I have to check if there is any service running on port mentioned. For this, command is netcat localhost 30000. When entered, this will require a password. I entered a random which lead to a message saying password is incorrect. It is known that the current level is password is stored in /etc/bandit_pass/bandit14.It is to be checked if the password stored in this file is the password for the service running on the mentioned port. For this command is cat /etc/bandit_pass/bandit14. Thus, we get a password, which I copied. Then next command is netcat localhost 30000. This reuires a password when entered, I entered the password I copied previously. +# This outputs correct and gives the password for the next level. Hence, we enter to the 15th level.