From 3a70fb6685d1fc1a1143aa9a1e7485da0f6dd84c Mon Sep 17 00:00:00 2001 From: Abhirupvasa Date: Sat, 19 Apr 2025 01:17:43 +0530 Subject: [PATCH 1/2] Abhirup Vasa Submission Over The Wire --- otw.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 otw.md diff --git a/otw.md b/otw.md new file mode 100644 index 0000000..a37f8d3 --- /dev/null +++ b/otw.md @@ -0,0 +1,30 @@ +Level 0: +Connected to the bandit server using ssh with the given username and password.Used the command: ssh bandit0@bandit.labs.overthewire.org -p 2220 +Level 1: +Password is stored in a file named '-'. Used cat ./- to access it. +Level 2: +Password is stored in a file named 'spaces in this filename'.Used cat "spaces in this filename" +Level 3: +Password is stored in a hidden file. Navigated to inhere directory using cd inhere, then listed all files using ls -a, then used cat .hiddenfile +Level4: +Password is stored in only human readable file in the inhere directory. Navigated to inhere directory using cd inhere, then used ls -lh and then used cat file to get the password. +Level5: +Navigated to inhere directory using cd inhere, then used find . -type f -size 1033c ! -executable and then manually used the command file to find whether the text is ASCII then used the cat. +Level6: +I first used cd /.. to navigate to /. Then used find . -type f -user bandit7 -group bandit6 -size 33c then cat. +Level7: +First used the command grep -n "millionth" data.txt and got it. Then used the command grep "millionth" data.txt to get it directly. +Level8: +Used the command sort data.txt | uniq -u, as uniq can only find the unique strings if the repeayedly occuring string occur together. +Level9: +Used the command strings data.txt | grep ==* and then selected from the list appeared. The strings data.txt will give the strings available and then grep ==* +Level10: +Directly used the command base64 -d data.txt to decode the content of the file. +Level11: +Used the command cat data.txt |tr [a-z] [n-za-m] | tr [A-Z] [N-ZA-M] to first update the small alphabets and the bigger ones +Level12: +First used xxd -r data.txt to convert the hex dump to binary. Then I setup a dir in /tmp as told then used the mv, cp commands, and the file command(to find whether it is compressed by gzip or bzip2 or tar archived) and then used the appropriate commands to decompress it or to extract files from it. +Level13: +Password is stored in /etc/bandit_pass/bandit14. So I have to login into bandit14 to access it. First located the private ssh key inside a file in the home directory of the bandit13. Then setup the correct permissions and then used ssh to log into bandit14 user on the localhost. Then I went to the address /etc/bandit_pass/bandit14 and found the key. +Level 14: +I have already logged into the user bandit14. Now submitted the password to port 30000 on localhost using telnet. From 21cc434f707480709286e959dea01863736ca48d Mon Sep 17 00:00:00 2001 From: Abhirupvasa Date: Tue, 13 May 2025 23:37:38 +0530 Subject: [PATCH 2/2] Create Task2_Netflix_Inventory_Managemnet_Submission --- Task2_Netflix_Inventory_Managemnet_Submission | 488 ++++++++++++++++++ 1 file changed, 488 insertions(+) create mode 100644 Task2_Netflix_Inventory_Managemnet_Submission diff --git a/Task2_Netflix_Inventory_Managemnet_Submission b/Task2_Netflix_Inventory_Managemnet_Submission new file mode 100644 index 0000000..d975b14 --- /dev/null +++ b/Task2_Netflix_Inventory_Managemnet_Submission @@ -0,0 +1,488 @@ +#include +#include +#include +#include +using namespace std; +namespace fs = std::filesystem; + +// Base class representing common properties of contents +class contents{ + public: + string title; + string genre; + float rating; + bool is_rented; + bool is_purchased; +}; + +// Derived class representing a Movie +class movie : public contents{ + public: + int duration; + float rent_cost; + float purchase_cost; + + movie(string t, string g, float r, int d, float r_cost, float p_cost){ + title = t; + genre = g; + rating = r; + is_rented = false; + is_purchased = false; + duration = d; + rent_cost = r_cost; + purchase_cost = p_cost; + } +}; + +// Derived class representing a TV Show +class tv_show : public contents{ + public: + int nseasons; + int nepisodes_per_season; + float rent_cost; + float purchase_cost; + + tv_show(string t, string g, float r, int ns, int neps, float r_cost, float p_cost){ + title = t; + genre = g; + rating = r; + is_rented = false; + is_purchased = false; + nseasons = ns; + nepisodes_per_season = neps; + rent_cost = r_cost; + purchase_cost = p_cost; + } +}; + +// Handles user signup process +void signup() { + string username,password; + float due = 0; + cout << "ENTER YOUR USERNAME IN THE FORM OF SNAKE_CASE IDENTIFIER (e.g. abc_def)" << endl; + cin >> username; + + string filepath = "data/users" + username + ".txt"; + if (fs::exists(filepath)){ + cout << "Username already taken!! Try another one" << endl; //Uniqueness of username + return; + } + + //Stored all usernames alog with their dues + fs::create_directories("data/users"); + std::ofstream all_file("data/users/allusernames.txt", ios::app); + all_file << username << " " << due << "\n"; + + cout << "Enter password" << endl; + cin >> password; + + std::ofstream file(filepath); + file << username << " " << password << "\n"; + file.close(); + + cout << "Signup successful."; + return; +} + + +//Handles user login +bool login() { + string username,password; + cout << "Enter your username" << endl; + cin >> username; + + string filepath = "data/users/" + username + ".txt"; + if (!fs::exists(filepath)){ + cout << "User not found!" << endl; + return; + } + + std::ifstream file(filepath); + string stored_username, stored_password; + file >> stored_username >> stored_password; + file.close(); + + cout << "Enter password" << endl; + cin >> password; + + if(password == stored_password){ + cout << "Login successful" << "\n" << "Welcome" << endl; + return true; + } + else{ + cout << "Login failed" << endl; + return false; + } +} + +// Creates the admin user file +void admin_signup(){ + fs::create_directory("data/admin"); + std::ofstream file("data/admin/owner.txt"); + file << "owner" << " " << "admin"; +} + +// Handles admin login +bool admin_login(){ + string username,password; + cout << "Enter your username" << endl; + cin >> username; + + string filepath = "data/admin" + username + ".txt"; + if (!fs::exists(filepath)){ + cout << "Admin not found!" << endl; + return false; + } + + string stored_username, stored_password; + std::ifstream file(filepath); + file >> stored_username >> stored_password; + + cout << "Enter password" << endl; + cin >> password; + if(password == stored_password){ + cout << "login successful!" << endl; + return true; + } + else{ + cout << "login failed" << endl; + return false; + } +} + +// Saves a movie to file system +void upload_movie(movie inst){ + string path = "data/movies/" + inst.genre ; + fs::create_directories(path); + + string all_path = "data/movies/all_movies.txt"; + std::ofstream all_file(all_path, ios::app); + all_file << inst.title << " " << inst.genre << "\n"; + + string ind_path = "data/movies/" + inst.genre + "/all_movies.txt"; + std::ofstream ind_file(ind_path, ios::app); + ind_file << inst.title << "\n"; + + string filepath = "data/movies/" + inst.genre + "/" + inst.title + ".txt"; + + std::ofstream file(filepath); + file << "Title :" << inst.title << "\n"; + file << "Genre :" << inst.genre << "\n"; + file << "Rating :" << inst.rating << "\n"; + file << "Duration :" << inst.duration << "\n"; + file << "Rent Cost per month:" << inst.rent_cost << "\n"; + file << "Purchase Cost :" << inst.purchase_cost << "\n"; + if(inst.is_purchased){ + file << "Purchased : Yes\n"; + } + else{ + file << "Purchased : No\n"; + } + + if(inst.is_rented){ + file << "Rented : Yes\n"; + } + else{ + file << "Rented : No\n"; + } + file.close(); + + cout << "Movie saved in " << inst.genre << "genre" << endl; +} + +// Checks if movie exists +bool check_movie(string title){ + std::ifstream file("data/movies/allmovies.txt"); + string stored_title; + string genre; + while(file >> stored_title >> genre){ + if(stored_title == title){ + cout << "Movie found"; + + string line; + ifstream nfile("data/movies/"+ genre+ "/" + title + ".txt"); + while(getline(nfile, line)){ + cout << line << endl; + } + file.close(); + return true; + } + } + return false; +} + +//Saves a TV show to the file system +void upload_tvshow(tv_show inst){ + string path = "data/tvshows/" + inst.title + ".txt"; + fs::create_directories(path); + + string all_path = "data/tvshows/alltvshows.txt"; + std::ofstream all_file(all_path, ios::app); + all_file << inst.title << " " << inst.genre << "\n"; + + std::ofstream file(path); + file << "Title :" << inst.title << "\n"; + file << "Rating :" << inst.rating << "\n"; + file << "Number of seasons :" << inst.nseasons << "\n"; + file << "Numeber of episodes per season :" << inst.nepisodes_per_season << "\n"; + file << "Rent Cost per month:" << inst.rent_cost << "\n"; + file << "Purchase Cost :" << inst.purchase_cost << "\n"; + if(inst.is_purchased){ + file << "Purchased : Yes\n"; + } + else{ + file << "Purchased : No\n"; + } + + if(inst.is_rented){ + file << "Rented : Yes\n"; + } + else{ + file << "Rented : No\n"; + } + file.close(); + + cout << "TV show is saved successfully"; +} + +//Checks if the TV show exists +bool check_tvshows(string title){ + std::ifstream file("data/tvshpws/alltvshows.txt"); + string stored_title; + while(file >> stored_title){ + if(stored_title == title){ + cout << "TV show found"; + + string line; + ifstream nfile("data/tvshows/" + title + ".txt"); + while(getline(nfile, line)){ + cout << line << endl; + } + file.close(); + return true; + } + } + return false; +} + +//Gets the current date for the renting process +string get_date(){ + time_t now = time(0); // Get the current time in sec + tm *ltm = localtime(&now); // Convert to local time (date) + + int day = ltm->tm_mday; + int month = ltm->tm_mon + 1; + int year = 1900 + ltm->tm_year; + + string date = to_string(day) + "-" + to_string(month) + "-" + to_string(year); + return date; +} + +//Gets the date of return corresponding to the date of renting +string date_of_return(){ + time_t now = time(0); + now = now + 2628288; // A month has 26,28,288 seconds + tm *ltm = localtime(&now); + + int day = ltm->tm_mday; + int month = ltm->tm_mon + 1; + int year = 1900 + ltm->tm_year; + + string date = to_string(day) + "-" + to_string(month) + "-" + to_string(year); + return date; +} + +//Function for updating the dues in the all usernames file +void update_due(float price, string username){ + string filepath = "data/users/allusernames.txt"; + std::ifstream file(filepath, ios::app); + string stored_username; + float stored_due; + while(file >> stored_username >> stored_due){ + if(stored_username == username){ + stored_due += price; + break; + } + } + return; +} + +//For purchasing movie +void purchase_movie(string title, string username){ + string filepath = "data/users/" + username + ".txt"; + std::ofstream file(filepath, ios::app); + file << "Movie Purchased : " << title << "\n"; + file.close(); +} + +//For purchasing the TV show +void purchase_tvshow(string title, string username){ + string filepath = "data/users/" + username + ".txt"; + std::ofstream file(filepath, ios::app); + file << "TV show Purchased : " << title << "\n"; + file.close(); +} + +//For renting the movie +void rent_movie(string title, string username){ + string filepath = "data/users/" + username + ".txt"; + std::ofstream file(filepath, ios::app); + file << "Movie Rented : " << title << "\n"; + file << "Date Rented : " << get_date() << "\n"; + file << "Last Date of return :" << date_of_return() << "\n"; + file.close(); +} + +//For renting the TV show +void rent_tvshow(string title, string username){ + string filepath = "data/users/" + username + ".txt"; + std::ofstream file(filepath, ios::app); + file << "Movie Rented : " << title << "\n"; + file << "Date Rented : " << get_date() << "\n"; + file << "Last Date of return :" << date_of_return() << "\n"; + file.close(); +} + +//A general function to print the contents out of a file +void print_content(string filepath){ + ifstream file(filepath); + string line; + while (getline(file, line)){ + cout << line << endl; + } +} + +int main(){ + while (true){ + admin_signup(); + + int choice; + cout << "\n1.User Sign Up\n2. User Login\n3.Admin Login\n4. Exit\nEnter choice: "; + cin >> choice; + if (choice == 1){ + signup(); + } + if (choice == 2){ + if(login()){ + cout << "Such a boring summer \n"; + int response; + cout << "Ready for some screen-time magic? Press 1 to dive into a blockbuster movie, or 2 to binge a top-tier TV show! "; + cin >> response; + if(response == 1){ + int choice; + cout << "Your movie adventure begins here! Press 1 to explore our full movie vault, or press 2 to hunt down that perfect flick you're craving"; + cin >> choice; + if(choice == 1){ + string genre; + cout << "What are you in the mood for today?\n"; + cout << "Type the genre you'd like to explore from the list below (in small letters, please!):\n"; + cout << "action, adventure, comedy, drama, horror, science fiction, romance, thriller, fantasy, mystery\n"; + cin >> genre; + print_content("data/movies/" + genre + "/all_movies.txt");//Prints all movies in that genre + string name; + cout << "Once you've found the one you'd like to watch, type the exact movie title in small letters to continue or type exit to give a fresh start"; + cin >> name; + if(name == "exit") continue; + print_content("data/movies/"+ genre+ "/" + name + ".txt");//Prints the info about that particular movie + int choice; + cout << "Press 1 to rent the movie or 2 to purchase it or 3 to get back to main menu"; + cin >> choice; + string username; + cout << "Enter your username again"; + cin >> username; + if(choice == 1){ + rent_movie(name, username); + } + else if(choice == 2){ + purchase_movie(name, username); + } + else if(choice == 3) continue; + } + else if(choice == 2){ + print_content("data/tvshows/alltvshows.txt"); + string name; + cout << "Once you've found the one you'd like to watch, type the exact title in small letters to continue or type exit to give a fresh start"; + cin >> name; + if(name == "exit") continue; + print_content("data/tvshows/" + name + ".txt"); + int choice; + cout << "Press 1 to rent the tvshow or 2 to purchase it or 3 to get back to main menu"; + cin >> choice; + string username; + cout << "Enter your username again"; + cin >> username; + if(choice == 1){ + rent_tvshow(name, username); + } + else if(choice == 2){ + purchase_tvshow (name, username); + } + else if(choice == 3) continue; + } + } + } + } + if(choice == 3){ + if(admin_login()){ + int response; + cin >> response; + cout << "Enter 1 to upload a movie or tv show, press 2 to delete one and 3 to checkout the dues"; + if(response == 1){ + int choice; + cout << "Enter 1 to upload a movie or 2 to upload a tv show"; + cin >> choice; + if(choice == 1){ + cout << "Enter the following details of the movie : "; + string title, genre; + float rating, rent_cost, purchase_cost; + int duration; + + cout << "Enter title: "; + cin >> title; + cout << "Enter genre: "; + cin >> genre; + cout << "Enter rating: "; + cin >> rating; + cout << "Enter duration (in minutes): "; + cin >> duration; + cout << "Enter rent cost: "; + cin >> rent_cost; + cout << "Enter purchase cost: "; + cin >> purchase_cost; + + movie m(title, genre, rating, duration, rent_cost, purchase_cost); + upload_movie(m); + } + if (choice == 2){ + cout << "Enter the following details of the tv show : "; + + string title, genre; + float rating, rent_cost, purchase_cost; + int nseasons, nepisodes; + + cout << "Enter title: "; + cin >> title; + cout << "Enter genre: "; + cin >> genre; + cout << "Enter rating: "; + cin >> rating; + cout << "Enter number of seasons: "; + cin >> nseasons; + cout << "Enter number of episodes per season: "; + cin >> nepisodes; + cout << "Enter rent cost: "; + cin >> rent_cost; + cout << "Enter purchase cost: "; + cin >> purchase_cost; + + tv_show show(title, genre, rating, nseasons, nepisodes, rent_cost, purchase_cost); + upload_tvshow(show); + } + } + else if(response == 3){ + print_content("data/users/allusernames.txt");//shows the dues + } + } + } + } +}