diff --git a/Aerial submission [MConverter.eu].md b/Aerial submission [MConverter.eu].md new file mode 100644 index 0000000..54d9b93 --- /dev/null +++ b/Aerial submission [MConverter.eu].md @@ -0,0 +1,168 @@ +**Bandit Wargames Writeup Code** + +Level 0: + +ssh command + +using code ssh -- p 2220 + +given password bandit0 + +Level 0 -1: + +Using cat command we read the contents of the readme file to gte the +required password. + +cat readme gives us the content of the readme file + +Level 1 - 2 : + +We need to find a file with name - + +We need to write command cat ./- in order to access the contents of the +file as directly using -- would result in an error as -- has a specific +function in linux shell. + +263JGJPfgU6LtdEvgfWU1XP5yac29mFx + +Level 2 -- 3: + +We need to access contents of a file named spaces in the filename + +We would use cat spaces\\ in\\ this\\ filename. + +MNk8KNH3Usiio41PRUEoDFPqfxLPlSmx + +Level 3 -- 4: + +We need to access content of a hidden file. + +We use command cd inhere to change directory from home to inhere. + +We then use ls -alps to list out all type of files. + +We then choose the hiding from you file and read the contents using cat. + +Level 4 -- 5: + +We need to find the only human readable file. + +For that, we need to access the type of file using find . -type f \| +xargs file command. + +Xargs file→ passes those file paths to the *file* command, which detects +and prints each file\'s type + +After ths we choose the file 007 as it is the only ASCII text type of +file + +Then use cat filename to access the password. + +Level 5 -- 6: + +We need to use command find . -type f -size 1033c to get the file. + +-size 1033c for the size and type f for the humamn readable condition. + +Level 6 -- 7: + +We need to use command cd inhere to change directory and then use ind / +-type f -user bandit7 -group bandit6 -size 33c 2\>/dev/null + +\- user for the user + +\- group for the group owner + +\- 2\>/dev/null: to remove all permission denied files. + +Level 7 -- 8: + +We need to find the password next to the word "millionth" + +So we use the command grep "millionth" data.txt + +grep command to find all the files which contain the word. + +Level 8 -- 9: + +The password is the line which occurs only once. + +We can use the sort filename.txt \| uniq -u command. + +If there are double lines, sort brings them together, while uniq -u +prints the unique lines. + +Level 9 -- 10: + +Using strings command we access all the strings of the file and by using +the grep "==" we find strings preceded by == + +strings data.txt \| grep '==' + +Level 10 -- 11: + +We use the grep '=' command the get the most password looking like base +64 encoded data. Then we use the base64 -d command to get the password. + +Strings data.txt \| grep '=' + +echo "base64 encoded" base64 -d + +We're using echo to ****feed the Base64-encoded string into the base64 +command****. + +Level 11-- 12: + +We need to find the rotated alphabets. + +For that we use the tr command. + +tr \'A-Za-z\' \'N-ZA-Mn-za-m\' \< data.txt + +\'A-Za-z\' -- matches the upper case and lower case letters + +'N-ZA-Mn-za-m\' -- Rotates them by 13 positions + +tr translates the lines. + +Level 12-- 13: + +We use the following code for de-compressing the file: + +mv data.bin final.gz (if its a gunzip compressed file) + +We rename the file to final + +Then we decompress it using gunzip. + +Gunzip final.gz . Now we check for the file type, which if still needs +to be compressed, will require from us to repeat the same steps. + +FO5dwFsc0cbaIiH0h8J2eUks2vdTDwAn + +Level 13-- 14: + +This level does not require any password but wants us to use our private +key instead of a password to login to level 14. For that, we need to +check first if our ssh key is private using cat sshkey.private. + +Then we need to change the mode so that only **we **are able to read or +write the file. Then we can use the private key to login. + +ssh -i sshkey.private bandit14@localhost -p 2220 + +**-i sshkey.private**: tells SSH to use ****your private key**** instead +of a password + +**bandit14@localhost**: log in as **bandit14** on the ****same +machine**** + +Level 14 -- 15: + +For this level we need to find a password to level 15-16 by giving a +localhost or password of level 14. + +The password to level 14 could be accessed by cat +/etc/bandit_pass/bandit14 + +Then writing nc localhost 30000 would allow us to write our password. diff --git a/Task 2/sarthak_s/Sarthak_transactions.txt b/Task 2/sarthak_s/Sarthak_transactions.txt new file mode 100644 index 0000000..e69de29 diff --git a/Task 2/sarthak_s/movie_rental.cpp b/Task 2/sarthak_s/movie_rental.cpp new file mode 100644 index 0000000..c959093 --- /dev/null +++ b/Task 2/sarthak_s/movie_rental.cpp @@ -0,0 +1,671 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +const int MAX_MOVIES = 100; + +string currentUser = ""; + +bool loginUser() { + string username, password; + cout << "Enter username: "; + cin >> username; + cout << "Enter password: "; + cin >> password; + + ifstream file("users.txt"); + string line; + while (getline(file, line)) { + stringstream ss(line); + string storedUser, storedPass; + getline(ss, storedUser, '|'); + getline(ss, storedPass); + if (storedUser == username && storedPass == password) { + currentUser = username; + cout << "Login successful. Welcome, " << username << "!\n"; + return true; + } + } + cout << "Invalid credentials.\n"; + return false; +} + +bool signupUser() { + string username, password; + cout << "Choose a username: "; + cin >> username; + + ifstream infile("users.txt"); + string line; + while (getline(infile, line)) { + stringstream ss(line); + string existingUser; + getline(ss, existingUser, '|'); + if (existingUser == username) { + cout << "Username already taken. Please choose another.\n"; + return false; + } + + } + + cout << "Choose a password: "; + cin >> password; + + ofstream outfile("users.txt", ios::app); + outfile << username << "|" << password << "\n"; + + ofstream userFile(username + "_transactions.txt"); + userFile.close(); + + currentUser = username; + cout << "Signup successful!\n"; + return true; +} + +void logTransaction(const string& username, const string& action, const string& title, double amount) { + ofstream file(username + "_transactions.txt", ios::app); + time_t now = time(0); + string date = ctime(&now); + date.pop_back(); // Remove newline + file << action << "|" << title << "|" << amount << "|" << date << "\n"; +} + + +class Movie { +private: + int id; + string title; + string genre; + int duration; + double rating; + bool isRented; + bool isPurchased; + double rentCost; + double purchaseCost; + string rentDate; + string returnDate; + +public: + Movie() : id(0), title(""), genre(""), duration(0), rating(0.0), isRented(false), isPurchased(false), rentCost(0.0), purchaseCost(0.0), rentDate(""), returnDate("") {} + + Movie(int id, string& title, string& genre, bool isRented, int duration, double rating, double rentCost, double purchaseCost) + : id(id), title(title), genre(genre), isRented(isRented), duration(duration), rating(rating), + rentCost(rentCost), purchaseCost(purchaseCost) {} + + + int getId() const { return id; } + string getTitle() const { return title; } + string getGenre() const { return genre; } + bool rented() const { return isRented; } + int getDuration() const { return duration;} + double getRating() const {return rating ;} + bool getIsPurchased() const { return isPurchased; } + void setIsPurchased(bool purchased) { isPurchased = purchased; } + + double getRentCost() const { return rentCost; } + void setRentCost(double cost) { rentCost = cost; } + + double getPurchaseCost() const { return purchaseCost; } + void setPurchaseCost(double cost) { purchaseCost = cost; } + + string getRentDate() const { return rentDate; } + void setRentDate(const string& date) { rentDate = date; } + + string getReturnDate() const { return returnDate; } + void setReturnDate(const string& date) { returnDate = date; } + + void rent() { isRented = true; } + void returnMovie() { isRented = false; } + bool purchased() const { return isPurchased; } + + + string serialize() const { + return to_string(id) + "|" + title + "|" + genre + "|" + + (isRented ? "1" : "0") + "|" + + to_string(duration) + "|" + + to_string(rating) + "|" + + to_string(rentCost) + "|" + + to_string(purchaseCost); +} + + void display() const { + cout << id << ". " << title << " (" << genre << ") [" << (isRented ? "RENTED" : "AVAILABLE") << "] " + << "[" << (isPurchased ? "PURCHASED" : "NOT PURCHASED") << "] " + << "(" << duration << " min) [" << rating << "/5.0] " + << "Rent Cost: $" << rentCost << ", Purchase Cost: $" << purchaseCost << "\n";} + + void set(int newId, string& newTitle, string& newGenre, bool status, int new_duration, double new_rating, double new_rentCost, double new_purchaseCost) { + id = newId; + title = newTitle; + genre = newGenre; + isRented = status; + duration = new_duration; + rating = new_rating; + rentCost = new_rentCost; + purchaseCost = new_purchaseCost; +} +}; + +class MovieManager { +private: + Movie movies[MAX_MOVIES]; + int movieCount; + const string fileName = "movies.txt"; + +public: + MovieManager() { + movieCount = 0; + loadMovies(); + } + + void loadMovies() { + movieCount = 0; + ifstream file(fileName); + if (!file.is_open()) return; + + string line; + while (getline(file, line) && movieCount < MAX_MOVIES) { + stringstream ss(line); + string idStr, title, genre, statusStr, durStr, ratStr, rentCostStr, purchaseCostStr; + + if (getline(ss, idStr, '|') && + getline(ss, title, '|') && + getline(ss, genre, '|') && + getline(ss, statusStr, '|') && + getline(ss, durStr, '|') && + getline(ss, ratStr, '|') && + getline(ss, rentCostStr, '|') && + getline(ss, purchaseCostStr)) { + + int id = stoi(idStr); + bool status = (statusStr == "1"); + int dur = stoi(durStr); + double rat = stod(ratStr); + double rentCost = stod(rentCostStr); + double purchaseCost = stod(purchaseCostStr); + + movies[movieCount++].set(id, title, genre, status, dur, rat, rentCost, purchaseCost); + } + } + + file.close(); +} + void saveMovies() const { + ofstream file(fileName); + for (int i = 0; i < movieCount; ++i) { + file << movies[i].serialize() << '\n'; + } + file.close(); + +} + + + + void browseMovies() const { + cout << "\n--- Movie List ---\n"; + for (int i = 0; i < movieCount; ++i) { + movies[i].display(); + } + } + + void rentMovie(int id) { + for (int i = 0; i < movieCount; ++i) { + if (movies[i].getId() == id) { + if (!movies[i].rented()) { + movies[i].rent(); + // Set rent date to current date + time_t now = time(0); + tm* ltm = localtime(&now); + char rentDate[11]; + strftime(rentDate, sizeof(rentDate), "%Y-%m-%d", ltm); + movies[i].setRentDate(rentDate); + + // Set return date to 10 days from now + now += 10 * 24 * 60 * 60; // Add 10 days in seconds + ltm = localtime(&now); + char returnDate[11]; + strftime(returnDate, sizeof(returnDate), "%Y-%m-%d", ltm); + movies[i].setReturnDate(returnDate); + + saveMovies(); + cout << "You rented \"" << movies[i].getTitle() << "\". Return by " << movies[i].getReturnDate() << ".\n"; + logTransaction(currentUser, "Rent", movies[i].getTitle(), movies[i].getRentCost()); + } else { + cout << "That movie is already rented.\n"; + } + return; + } + } + cout << "Movie not found.\n"; +} + void purchaseMovie(int id) { + for (int i = 0; i < movieCount; ++i) { + if (movies[i].getId() == id) { + if (!movies[i].getIsPurchased()) { + movies[i].setIsPurchased(true); + saveMovies(); + cout << "You purchased \"" << movies[i].getTitle() << "\" for $" << movies[i].getPurchaseCost() << ".\n"; + logTransaction(currentUser, "Purchase", movies[i].getTitle(), movies[i].getPurchaseCost()); + } else { + cout << "You have already purchased this movie.\n"; + } + return; + } + } + cout << "Movie not found.\n"; +} + +void viewRentedMovies() const { + cout << "\n--- Currently Rented Movies ---\n"; + bool found = false; + for (int i = 0; i < movieCount; ++i) { + if (movies[i].rented()) { + movies[i].display(); + cout << "Rented on: " << movies[i].getRentDate() << ", Return by: " << movies[i].getReturnDate() << "\n"; + found = true; + } + } + if (!found) { + cout << "No movies are currently rented.\n"; + } +} + +void viewPurchasedMovies() const { + cout << "\n--- Purchased Movies ---\n"; + bool found = false; + for (int i = 0; i < movieCount; ++i) { + if (movies[i].purchased()) { + movies[i].display(); + found = true; + } + } + if (!found) { + cout << "No movies have been purchased.\n"; + } +} + +void viewTotalCharges() const { + double totalRent = 0.0, totalPurchase = 0.0; + + for (int i = 0; i < movieCount; ++i) { + if (movies[i].rented()) { + totalRent += movies[i].getRentCost(); + } + if (movies[i].purchased()) { + totalPurchase += movies[i].getPurchaseCost(); + } + } + + cout << "\n--- Charges Summary ---\n"; + cout << "Total Rent Charges: $" << totalRent << "\n"; + cout << "Total Purchase Charges: $" << totalPurchase << "\n"; + cout << "-------------------------\n"; + cout << "Total Amount Due: $" << (totalRent + totalPurchase) << "\n"; +} + + void returnMovie(int id) { + for (int i = 0; i < movieCount; ++i) { + if (movies[i].getId() == id) { + if (movies[i].rented()) { + movies[i].returnMovie(); + saveMovies(); + cout << "You returned \"" << movies[i].getTitle() << "\".\n"; + } else { + cout << "The movie wasn't rented.\n"; + } + return; + } + } + cout << "Movie not found.\n"; + } + + void addMovie(int id, string& title, string& genre, int dur, double rat, double rentCost, double purchaseCost) { + if (movieCount >= MAX_MOVIES) { + cout << "Movie list is full.\n"; + return; + } + for (int i = 0; i < movieCount; ++i) { + if (movies[i].getId() == id) { + cout << "Movie ID already exists.\n"; + return; + } + } + movies[movieCount++].set(id, title, genre, false, dur, rat, rentCost, purchaseCost); + saveMovies(); + cout << "Movie added.\n"; +} + void deleteMovie(int id) { + bool found = false; + for (int i = 0; i < movieCount; ++i) { + if (movies[i].getId() == id) { + found = true; + for (int j = i; j < movieCount - 1; ++j) { + movies[j] = movies[j + 1]; + } + movieCount--; + saveMovies(); + cout << "Movie deleted.\n"; + break; + } + } + if (!found) cout << "Movie not found.\n"; + } + + void adminViewUserCharges() { + string username; + cout << "Enter username to view charges: "; + cin >> username; + + ifstream file(username + "_transactions.txt"); + if (!file.is_open()) { + cout << "No transaction file for user.\n"; + return; + } + + string line; + double total = 0; + cout << "\n--- Transactions for " << username << " ---\n"; + while (getline(file, line)) { + stringstream ss(line); + string action, title, amountStr, date; + getline(ss, action, '|'); + getline(ss, title, '|'); + getline(ss, amountStr, '|'); + getline(ss, date); + + double amount = stod(amountStr); + cout << action << ": " << title << " - $" << amount << " on " << date << "\n"; + total += amount; + } + cout << "Total Charges: $" << total << "\n"; +} + + void searchByTitle(const string& title) const { + cout << "\n--- Search Results (Exact Title: \"" << title << "\") ---\n"; + for (int i = 0; i < movieCount; ++i) { + if (movies[i].getTitle() == title) { + movies[i].display(); + return; + } + } + cout << "No matching movies found.\n"; + } + + void searchByGenre(const string& genre) const { + cout << "\n--- Movies in Genre: " << genre << " ---\n"; + bool found = false; + for (int i = 0; i < movieCount; ++i) { + if (movies[i].getGenre() == genre) { + movies[i].display(); + found = true; + } + } + if (!found) + cout << "No movies found in this genre.\n"; +} + +}; + +// ---------- Interface Code ---------- +void showUserMenu() { + cout << "\n--- User Menu ---\n"; + cout << "1. Browse Movies\n"; + cout << "2. Rent Movie\n"; + cout << "3. Return Movie\n"; + cout << "4. Purchase Movie\n"; + cout << "5. View Total Charges\n"; + cout << "6. View Rented Movies\n"; + cout << "7. View purchased movies\n"; + cout << "8. Search by Title\n"; + cout << "9. Search by Genre\n"; + cout << "10. Logout\n"; + cout << "Enter your choice: "; +} + +void adminMenu(MovieManager& manager) { + string password; + cout << "Enter admin password: "; + cin >> password; + + if (password != "admin123") { + cout << "Incorrect password.\n"; + return; + } + + int choice; + do { + cout << "\n--- Admin Menu ---\n"; + cout << "1. Add Movie\n"; + cout << "2. Delete Movie\n"; + cout << "3. View All Movies\n"; + cout << "4. Check charges due for any user\n"; + cout << "5. Logout\n"; + cout << "Enter your choice: "; + cin >> choice; + + switch (choice) { +case 1: + {int id, dur; + string title, genre; + double rat, rentCost, purchaseCost; + + cout << "Enter new movie ID: "; + cin >> id; + cin.ignore(); + + cout << "Enter movie title: "; + getline(cin, title); + + cout << "Enter genre: "; + getline(cin, genre); + + cout << "Enter the duration in minutes: "; + cin >> dur; + + cout << "Enter the rating: "; + cin >> rat; + + cout << "Enter the rent cost: "; + cin >> rentCost; + + cout << "Enter the purchase cost: "; + cin >> purchaseCost; + + manager.addMovie(id, title, genre, dur, rat, rentCost, purchaseCost); + break; + } + + case 2: { + int id; + cout << "Enter movie ID to delete: "; + cin >> id; + manager.deleteMovie(id); + break; + } + case 3: + manager.browseMovies(); + break; + case 4: + manager.adminViewUserCharges(); + break; + case 5: + cout << "Logging out from admin.\n"; + break; + default: + cout << "Invalid choice.\n"; + } + + } while (choice != 5); +} + +int main() { + MovieManager manager; + + int mode; + do { + cout << "\n1. User SignUp\n2. User Login\n3. Admin\n4. Exit \n----------------\nChoose: "; + cin >> mode; + + if (mode == 1) { + if(signupUser()){ + int choice; + do { + + showUserMenu(); + cin >> choice; + cin.ignore(); + + switch (choice) { + case 1: + manager.browseMovies(); + break; + case 2: { + int id; + cout << "Enter movie ID to rent: "; + cin >> id; + manager.rentMovie(id); + break; + } + case 3: { + int id; + cout << "Enter movie ID to return: "; + cin >> id; + manager.returnMovie(id); + break; + } + case 4: { + int id; + cout << "Enter movie id to purchase: "; + cin>>id; + manager.purchaseMovie(id); + break; + } + case 5: { + manager.viewTotalCharges(); + break; + } + case 6: { + manager.viewRentedMovies(); + break; + } + case 7: + { + manager.viewPurchasedMovies(); + break; + } + case 8: { + string title; + cout << "Enter movie title: "; + getline(cin, title); + manager.searchByTitle(title); + break; + } + + case 9: { + string genre; + cout << "Enter genre: "; + getline(cin, genre); + manager.searchByGenre(genre); + break; + } + case 10: + cout << "Logging out.\n"; + break; + default: + cout << "Invalid option.\n"; + } + } while (choice != 10); + } + } + else if(mode==2) + { + if(loginUser()) + { + + int choice; + do { + + showUserMenu(); + cin >> choice; + cin.ignore(); + + switch (choice) { + case 1: + manager.browseMovies(); + break; + case 2: { + int id; + cout << "Enter movie ID to rent: "; + cin >> id; + manager.rentMovie(id); + break; + } + case 3: { + int id; + cout << "Enter movie ID to return: "; + cin >> id; + manager.returnMovie(id); + break; + } + case 4: { + int id; + cout << "Enter movie id to purchase: "; + cin>>id; + manager.purchaseMovie(id); + break; + } + case 5: { + manager.viewTotalCharges(); + break; + } + case 6: { + manager.viewRentedMovies(); + break; + } + case 7: + { + manager.viewPurchasedMovies(); + break; + } + case 8: { + string title; + cout << "Enter movie title: "; + getline(cin, title); + manager.searchByTitle(title); + break; + } + + case 9: { + string genre; + cout << "Enter genre: "; + getline(cin, genre); + manager.searchByGenre(genre); + break; + } + case 10: + cout << "Logging out.\n"; + break; + default: + cout << "Invalid option.\n"; + } + } while (choice != 10); + + } + } + else if (mode == 3) { + adminMenu(manager); + } + else if (mode == 4) { + cout << "Exiting...\n"; + } + else { + cout << "Invalid selection.\n"; + } + } while (mode != 4); + + return 0; +} diff --git a/Task 2/sarthak_s/movies.txt b/Task 2/sarthak_s/movies.txt new file mode 100644 index 0000000..35f3b6a --- /dev/null +++ b/Task 2/sarthak_s/movies.txt @@ -0,0 +1,2 @@ +1|Titanic|Romance|0|150|4.200000|30.000000|45.000000 +2|Inglorious Basterds|Crime|0|162|4.800000|45.000000|60.000000 diff --git a/Task 2/sarthak_s/users.txt b/Task 2/sarthak_s/users.txt new file mode 100644 index 0000000..a2e2093 --- /dev/null +++ b/Task 2/sarthak_s/users.txt @@ -0,0 +1 @@ +Sarthak|1403