From 09df65b5be9135b7a193cb1c029055ab588855e6 Mon Sep 17 00:00:00 2001 From: stardustflicker Date: Fri, 18 Apr 2025 21:52:50 +0530 Subject: [PATCH 1/4] Add files via upload --- otw.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 otw.md diff --git a/otw.md b/otw.md new file mode 100644 index 0000000..0c2cc87 --- /dev/null +++ b/otw.md @@ -0,0 +1,65 @@ +OverTheWire (Levels 0–15) + +Level 0 +Task: Log into the Bandit server using SSH. +Solution: Connected using the command "ssh bandit0@bandit.labs.overthewire.org -p 2220" with the password 'bandit0'. + +Level 1 +Task: Locate and read a file named 'readme' in the home directory. +Solution: Ran "cat readme" to display the contents of the file, which contained the password. + +Level 2 +Task: Read a file that is named '-'. +Solution: Used "cat ./-" to tell the shell it's a file, not an option. + +Level 3 +Task: Find a hidden file inside the 'inhere' directory. +Solution: Used "ls -a inhere" to list hidden files and then "cat .hidden" to read its contents. + +Level 4 +Task: Find a non-executable file of exactly 1033 bytes in the 'inhere/' directory. +Solution: Ran "find inhere/ -type f -size 1033c ! -executable -exec cat {} \;" to locate and read it. + +Level 5 +Task: Similar to the previous level, but the target file is somewhere in a deeper directory structure. +Solution: Searched recursively using "find . -type f -size 1033c ! -executable -exec cat {} \;". + +Level 6 +Task: Look for a file that is 33 bytes in size, owned by user 'bandit7' and group 'bandit6'. +Solution: Used "find / -user bandit7 -group bandit6 -size 33c 2>/dev/null" to find and then "cat" to read it. + +Level 7 +Task: Read a file with spaces in its name. +Solution: Quoted the filename properly using "cat 'file with spaces in the name'". + +Level 8 +Task: Decode a password that is base64-encoded and stored in 'data.txt'. +Solution: Used the command "cat data.txt | base64 -d" to decode the contents. + +Level 9 +Task: Decrypt a password encoded with ROT13 (a simple Caesar cipher). +Solution: Ran "cat data.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m'" to convert it back to readable text. + +Level 10 +Task: Recover a password from a file presented as a hex dump. +Solution: Reversed the hex dump with "xxd -r data.txt" and filtered out printable characters using "strings". + +Level 11 +Task: Extract a password from a file that's base64 encoded and gzipped. +Solution: Decoded the file with "base64 -d", saved it as 'data.gz' and extracted it using "zcat". + +Level 12 +Task: Unpack a compressed file and encoded multiple times using different formats. +Solution: Used "base64 -d", followed by a sequence of tools like "gzip -d", "bzip2 -d", and "tar -xf" after identifying each layer with "file". + +Level 13 +Task: Log into the next level using a provided SSH private key. +Solution: Saved the key to a file, changed its permissions with "chmod 600", and connected using "ssh -i sshkey.private bandit13@bandit.labs.overthewire.org -p 2220". + +Level 14 +Task: Connect to a specific port on the server, send the password, and receive the next one. +Solution: Used "nc localhost 30000", pasted the password, and got the next one in response. + +Level 15 +Task: Similar to Level 14, but this time the connection is encrypted over SSL. +Solution: Ran "openssl s_client -connect localhost:30001", provided the password, and read the response for the next level. \ No newline at end of file From b0f2020e274518c15c15b433418a7a8e3777a675 Mon Sep 17 00:00:00 2001 From: stardustflicker Date: Fri, 18 Apr 2025 21:55:15 +0530 Subject: [PATCH 2/4] Delete otw.md --- otw.md | 65 ---------------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 otw.md diff --git a/otw.md b/otw.md deleted file mode 100644 index 0c2cc87..0000000 --- a/otw.md +++ /dev/null @@ -1,65 +0,0 @@ -OverTheWire (Levels 0–15) - -Level 0 -Task: Log into the Bandit server using SSH. -Solution: Connected using the command "ssh bandit0@bandit.labs.overthewire.org -p 2220" with the password 'bandit0'. - -Level 1 -Task: Locate and read a file named 'readme' in the home directory. -Solution: Ran "cat readme" to display the contents of the file, which contained the password. - -Level 2 -Task: Read a file that is named '-'. -Solution: Used "cat ./-" to tell the shell it's a file, not an option. - -Level 3 -Task: Find a hidden file inside the 'inhere' directory. -Solution: Used "ls -a inhere" to list hidden files and then "cat .hidden" to read its contents. - -Level 4 -Task: Find a non-executable file of exactly 1033 bytes in the 'inhere/' directory. -Solution: Ran "find inhere/ -type f -size 1033c ! -executable -exec cat {} \;" to locate and read it. - -Level 5 -Task: Similar to the previous level, but the target file is somewhere in a deeper directory structure. -Solution: Searched recursively using "find . -type f -size 1033c ! -executable -exec cat {} \;". - -Level 6 -Task: Look for a file that is 33 bytes in size, owned by user 'bandit7' and group 'bandit6'. -Solution: Used "find / -user bandit7 -group bandit6 -size 33c 2>/dev/null" to find and then "cat" to read it. - -Level 7 -Task: Read a file with spaces in its name. -Solution: Quoted the filename properly using "cat 'file with spaces in the name'". - -Level 8 -Task: Decode a password that is base64-encoded and stored in 'data.txt'. -Solution: Used the command "cat data.txt | base64 -d" to decode the contents. - -Level 9 -Task: Decrypt a password encoded with ROT13 (a simple Caesar cipher). -Solution: Ran "cat data.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m'" to convert it back to readable text. - -Level 10 -Task: Recover a password from a file presented as a hex dump. -Solution: Reversed the hex dump with "xxd -r data.txt" and filtered out printable characters using "strings". - -Level 11 -Task: Extract a password from a file that's base64 encoded and gzipped. -Solution: Decoded the file with "base64 -d", saved it as 'data.gz' and extracted it using "zcat". - -Level 12 -Task: Unpack a compressed file and encoded multiple times using different formats. -Solution: Used "base64 -d", followed by a sequence of tools like "gzip -d", "bzip2 -d", and "tar -xf" after identifying each layer with "file". - -Level 13 -Task: Log into the next level using a provided SSH private key. -Solution: Saved the key to a file, changed its permissions with "chmod 600", and connected using "ssh -i sshkey.private bandit13@bandit.labs.overthewire.org -p 2220". - -Level 14 -Task: Connect to a specific port on the server, send the password, and receive the next one. -Solution: Used "nc localhost 30000", pasted the password, and got the next one in response. - -Level 15 -Task: Similar to Level 14, but this time the connection is encrypted over SSL. -Solution: Ran "openssl s_client -connect localhost:30001", provided the password, and read the response for the next level. \ No newline at end of file From 1dd2ba61a1934b69d012f96b8588d7cd6c6a7eae Mon Sep 17 00:00:00 2001 From: stardustflicker Date: Fri, 18 Apr 2025 22:01:04 +0530 Subject: [PATCH 3/4] Add files via upload --- otw.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 otw.md diff --git a/otw.md b/otw.md new file mode 100644 index 0000000..0c2cc87 --- /dev/null +++ b/otw.md @@ -0,0 +1,65 @@ +OverTheWire (Levels 0–15) + +Level 0 +Task: Log into the Bandit server using SSH. +Solution: Connected using the command "ssh bandit0@bandit.labs.overthewire.org -p 2220" with the password 'bandit0'. + +Level 1 +Task: Locate and read a file named 'readme' in the home directory. +Solution: Ran "cat readme" to display the contents of the file, which contained the password. + +Level 2 +Task: Read a file that is named '-'. +Solution: Used "cat ./-" to tell the shell it's a file, not an option. + +Level 3 +Task: Find a hidden file inside the 'inhere' directory. +Solution: Used "ls -a inhere" to list hidden files and then "cat .hidden" to read its contents. + +Level 4 +Task: Find a non-executable file of exactly 1033 bytes in the 'inhere/' directory. +Solution: Ran "find inhere/ -type f -size 1033c ! -executable -exec cat {} \;" to locate and read it. + +Level 5 +Task: Similar to the previous level, but the target file is somewhere in a deeper directory structure. +Solution: Searched recursively using "find . -type f -size 1033c ! -executable -exec cat {} \;". + +Level 6 +Task: Look for a file that is 33 bytes in size, owned by user 'bandit7' and group 'bandit6'. +Solution: Used "find / -user bandit7 -group bandit6 -size 33c 2>/dev/null" to find and then "cat" to read it. + +Level 7 +Task: Read a file with spaces in its name. +Solution: Quoted the filename properly using "cat 'file with spaces in the name'". + +Level 8 +Task: Decode a password that is base64-encoded and stored in 'data.txt'. +Solution: Used the command "cat data.txt | base64 -d" to decode the contents. + +Level 9 +Task: Decrypt a password encoded with ROT13 (a simple Caesar cipher). +Solution: Ran "cat data.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m'" to convert it back to readable text. + +Level 10 +Task: Recover a password from a file presented as a hex dump. +Solution: Reversed the hex dump with "xxd -r data.txt" and filtered out printable characters using "strings". + +Level 11 +Task: Extract a password from a file that's base64 encoded and gzipped. +Solution: Decoded the file with "base64 -d", saved it as 'data.gz' and extracted it using "zcat". + +Level 12 +Task: Unpack a compressed file and encoded multiple times using different formats. +Solution: Used "base64 -d", followed by a sequence of tools like "gzip -d", "bzip2 -d", and "tar -xf" after identifying each layer with "file". + +Level 13 +Task: Log into the next level using a provided SSH private key. +Solution: Saved the key to a file, changed its permissions with "chmod 600", and connected using "ssh -i sshkey.private bandit13@bandit.labs.overthewire.org -p 2220". + +Level 14 +Task: Connect to a specific port on the server, send the password, and receive the next one. +Solution: Used "nc localhost 30000", pasted the password, and got the next one in response. + +Level 15 +Task: Similar to Level 14, but this time the connection is encrypted over SSL. +Solution: Ran "openssl s_client -connect localhost:30001", provided the password, and read the response for the next level. \ No newline at end of file From 7944a69c5735a4e111ee2f7be0de24e05d1ce31b Mon Sep 17 00:00:00 2001 From: stardustflicker Date: Wed, 14 May 2025 00:02:55 +0530 Subject: [PATCH 4/4] Assignment 2 Shruti Sharma --- inventory.txt | 3 + netflix.cpp | 381 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 384 insertions(+) create mode 100644 inventory.txt create mode 100644 netflix.cpp diff --git a/inventory.txt b/inventory.txt new file mode 100644 index 0000000..45c862b --- /dev/null +++ b/inventory.txt @@ -0,0 +1,3 @@ +Inception SciFi Movie PG13 120.0 300.0 +Titanic Romance Movie PG13 100.0 250.0 +BreakingBad Crime TV PG 80.0 500.0 diff --git a/netflix.cpp b/netflix.cpp new file mode 100644 index 0000000..19cd36f --- /dev/null +++ b/netflix.cpp @@ -0,0 +1,381 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +namespace fs=std::filesystem; + +class Content { +protected: + string title; + string genre; + string rating; + bool is_rented; + bool is_purchased; + +public: + Content() : is_rented(false), is_purchased(false) {} + Content(string t, string g, string r) + : title(t), genre(g), rating(r), is_rented(false), is_purchased(false) {} + virtual ~Content() {} +}; + +class Movie : public Content { + int duration; // in minutes + double rent_cost; + double purchase_cost; + +public: + Movie(string t, string g, string r, int d, double rc, double pc) + : Content(t, g, r), duration(d), rent_cost(rc), purchase_cost(pc) {} + + void display() const override { + cout << "Movie: " << title << "\nGenre: " << genre << "\nRating: " << rating<< "\nDuration: " << duration << " mins\nRent: ₹" << rent_cost<< "\nPurchase: ₹" << purchase_cost << endl;} +}; + +class TVShow : public Content { + int seasons; + int episodes_per_season; + double rent_cost; + double purchase_cost; + +public: + TVShow(string t, string g, string r, int s, int eps, double rc, double pc) + : Content(t, g, r), seasons(s), episodes_per_season(eps), rent_cost(rc), purchase_cost(pc) {} + + void display() const override { + cout << "TV Show: " << title << "\nGenre: " << genre << "\nRating: " << rating<< "\nSeasons: " << seasons << ", Episodes/Season: " << episodes_per_season << "\nRent (per season): ₹" << rent_cost << "\nPurchase (per season): ₹" << purchase_cost << endl;} +}; + +class ContentManager { + vector inventory; + +public: + ~ContentManager() { + for (auto c : inventory) delete c; + } + + void loadInventory() { + ifstream fin("inventory.txt"); + string type, title, genre, rating; + double rent, purchase; + while (fin >> title >> genre >> type >> rating >> rent >> purchase) { + if (type == "Movie") { + inventory.push_back(new Movie(title, genre, rating, 120, rent, purchase)); // sample duration + } else if (type == "TV") { + inventory.push_back(new TVShow(title, genre, rating, 3, 10, rent, purchase)); // sample seasons/eps + } + } + fin.close(); + } + + void listAll() { + cout << "Available Content:\n"; + for (auto c : inventory) c->display(); + } + + void searchByGenre(const string& g) { + for (auto c : inventory) { + if (c->getGenre() == g) { + c->display(); + } + } + } + + void rentContent(const string& title, const string& userFile) { + for (auto c : inventory) { + if (c->getTitle() == title) { + ofstream fout(userFile, ios::app); + fout << "RENTED: " << c->getTitle() << " Rent Cost: " << c->getRentCost() << "\n"; + fout.close(); + cout << "Rented successfully.\n"; + return; + } + } + cout << "Content not found.\n"; + } + + void purchaseContent(const string& title, const string& userFile) { + for (auto c : inventory) { + if (c->getTitle() == title) { + ofstream fout(userFile, ios::app); + fout << "PURCHASED: " << c->getTitle() << " Cost: " << c->getPurchaseCost() << "\n"; + fout.close(); + cout << "Purchased successfully.\n"; + return; + } + } + cout << "Content not found.\n"; + } + Content* findByTitle(const string& t) { + for (auto c : inventory) { + if (c->getTitle() == t) return c; + } + return nullptr; + } + +}; + + +class user { +protected: + string username; + string password; + ContentManager &manager; +public: + User(const string &uname, const string &pwd, const ContentManager &m) : username(uname), password(pwd), ContentManager(m) {} + string getusername() const { + return username;} + string getpassword() const { + return password;} + void rentContent() { + string title; + cout << "Enter title to rent: "; + cin.ignore(); + getline(cin, title); + + ofstream fout(username + "_data.txt", ios::app); + fout << "RENTED: " << title << " on " << time(0) << endl; + cout << "Content rented successfully.\n"; + } + + void viewRented() { + ifstream fin(username + "_data.txt"); + string line; + cout << "--- Your Rented Content ---\n"; + while (getline(fin, line)) { + if (line.find("RENTED") != string::npos) + cout << line << endl; + } + } + + void viewCharges() { + ifstream fin(username + "_data.txt"); + string line; + double total = 0.0; + + while (getline(fin, line)) { + size_t pos = line.find("Cost:"); + if (pos != string::npos) { + string cost_str = line.substr(pos + 5); // Skip past "Cost:" + try { + total += stod(cost_str); + } catch (...) { + cerr << "Failed to parse cost in line: " << line << endl; + } + } + } + + cout << "Total charges due: ₹" << total << endl; +} + + void browseContent() { + ifstream fin("inventory.txt"); + if (!fin) { + cout << "No content available.\n"; + return; + } + + Content c; + cout << "\n--- Available Content ---\n"; + while (fin >> c.title >> c.genre >> c.type >> c.rating >> c.rent_cost >> c.purchase_cost) { + c.display(); + } + } + + void usermenu() { + int choice; + do { + cout << "\nUser Menu\n1. Browse Content\n2. Rent\n3. View Rented\n4. View Charges\n5. Logout\n"; + cout << "Enter choice: "; + cin >> choice; + + switch (choice) { + case 1: browseContent(); break; + case 2: rentContent(); break; + case 3: viewRented(); break; + case 4: viewCharges(); break; + case 5: cout << "Logging out...\n"; break; + default: cout << "Invalid option.\n"; + } + } while (choice != 5); + } +}; + +void menu(); +bool uname_exist(string &username); +void signup(); +void login(); +void adminlogin(); +void adminmenu(); + +int main(){ +if (!fs::exists(data/users){ + fs::create(data/users);} +menu(); +} + +void menu(){ + int choice; + do{ + cout<<"Netflix\n"; + cout<<"1. Login\n"; + cout<<"2. Signin\n"; + cout<<"3. Admin Login\n"; + cout<<"Enter your choice: "; + cin>>choice; + switch(choice){ + case 1: + login(); + break; + case 2: + signup(); + break; + case 3: + adminlogin(); + break; + default: + cout<<"Invalid choice"; + +void signup(){ + string uname, pwd; + cout<<"For signing up, enter a unique username :"; + cin>>uname; + if (uname_exist(uname)){ + cout<<"Username exists, please enter another username"; + return;} + + cout<<"\nEnter password :"; + cin>>pwd; + + ofstream outfile("users.txt", std::ios::app); + outfile<>uname; + cout<<"Enter your password :"; + cin>>pwd; + ifstream fin("users.txt"); + string u,p; + while(fin>>u>>p) + if(u==uname && p= pwd) { + cout<<"Login successful.\n"; + User user(uname,pwd); + user.menu(); + break;} + else continue; + cout<<"Invalid credentials. Try again\n"; + usermenu();} + + +void adminlogin(){ + string pwrd; + cout<<"Enter password :"; + cin>>pwrd; + if(pwrd==adminpassword) + adminmenu(); + else{ + cout<<"Wrong password"; + adminlogin();} + } + +void adminmenu(){ + int choice; + do { + cout << "\n🎬 Admin Menu\n1. Add Content\n2. View User Charges\n3. Logout\n"; + cout << "Enter choice: "; + cin >> choice; + + switch (choice) { + case 1: addContent(); break; + case 2: { + string uname; + cout << "Enter username: "; + cin >> uname; + viewUserCharges(uname); + break; + } + case 3: cout << "Logging out...\n"; break; + default: cout << "Invalid option.\n"; + } + } while (choice != 3); + } +};} + + +class Admin { + const string admin_user = "admin"; + const string admin_pass = "admin123"; + +public: + bool login(const string& u, const string& p) { + return (u == admin_user && p == admin_pass); + } + + void addContent() { + Content c; + cout << "Enter title: "; cin >> c.title; + cout << "Enter genre: "; cin >> c.genre; + cout << "Enter type (Movie/TV): "; cin >> c.type; + cout << "Enter rating: "; cin >> c.rating; + cout << "Enter rent cost: "; cin >> c.rent_cost; + cout << "Enter purchase cost: "; cin >> c.purchase_cost; + + ofstream fout("inventory.txt", ios::app); + fout << c.title << " " << c.genre << " " << c.type << " " + << c.rating << " " << c.rent_cost << " " << c.purchase_cost << "\n"; + + cout << "Content added.\n"; + } + + void viewUserCharges(const string& uname) { + ifstream fin(uname + "_data.txt"); + if (!fin) { + cout << "No such user.\n"; + return; + } + + cout << "--- Transactions for " << uname << " ---\n"; + string line; + while (getline(fin, line)) { + cout << line << "\n"; + } + } + + void menu() { + int choice; + do { + cout << "\n🎬 Admin Menu\n1. Add Content\n2. View User Charges\n3. Logout\n"; + cout << "Enter choice: "; + cin >> choice; + + switch (choice) { + case 1: addContent(); break; + case 2: { + string uname; + cout << "Enter username: "; + cin >> uname; + viewUserCharges(uname); + break; + } + case 3: cout << "Logging out...\n"; break; + default: cout << "Invalid option.\n"; + } + } while (choice != 3); + } +}; + + + + +