Question

Write a Python (3) program to simulate** a buffer overflow (this is a new script, not...

Write a Python (3) program to simulate** a buffer overflow (this is a new script, not part of the intranet assignment), then implement input validation to prevent it. There are two parts to this assignment:

1) The program should display a welcome message and prompt the user for a username. Create a simulated buffer overflow condition by allowing a user to input more data than the size of the allocated memory (causing the program to crash).

2) Implement input validation to mitigate the simulated overflow vulnerability. Check that the username entered has a minimum length of 8 characters and a maximum of 25 characters. If the user enters a username length outside those limits, return an error message and prompt the user to re-enter the username.

Please submit two python files (one for part 1, and another for part 2) associated with your assignment, as well as instructions for testing your programs (README.txt).

if it need a input.txt, please help me to create one,

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part 1: Following is the program which raises the exception.

print('Welcome User')
username = input('Enter the name: ')
if len(username) > 25:
    raise Exception('The character length should be less than 25')

Following is the snippet of the output

Part 2: For this part, we need to raise the exception as well as handle the same.

Following is the code for the same.

print('Welcome User')
done_input = False
while not done_input:
    username = input('Enter the username: ')
    try:
        if len(username) < 8 or len(username) > 25:
            raise Exception()
        else:
            done_input = True
    except:
        print('Username length should be between 8 and 25')
print('Welcome ' + str(username))


Friend, If you have any doubts in understanding do let me know in the comment section. I will be happy to help you further.
Thanks

Add a comment
Know the answer?
Add Answer to:
Write a Python (3) program to simulate** a buffer overflow (this is a new script, not...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates...

    Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates user input 15 pts Morse Code Function Created 10 pts Function Uses Parameters to get input message 15 pts Function successfully converts passed message to Morse Code and returns the Morse Code equivalent of message 45 pts Program calls Morse Code function and outputs the result of the function (i.e. the actual Morse Code) 15 pts Main Function Requirement Part 2 MUST have a...

  • Create a python script to manage a user list that can be modified and saved to...

    Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...

  • in Python: Write a program that allows the user to enter a number between 1-5 and...

    in Python: Write a program that allows the user to enter a number between 1-5 and returns an animal fact based on what the user entered. The program should 1. Continue to run until the user enters “quit” to terminate the program, and 2. Validate the user’s input (the only acceptable input is 1, 2, 3, 4, 5 or “quit”). You can use the following animal facts: An octopus is a highly intelligent invertebrate and a master of disguise. Elephants...

  • two part question - answered in Python 3 2). Decision Structure: A travel agency is checking...

    two part question - answered in Python 3 2). Decision Structure: A travel agency is checking whether its tours are good for customers. It follows the table below to label each tour. (e.g., if a tour has 6 destinations and its price is $600, then it should be labelled as ‘expensive’.) Number of Destinations Price Label <5 <300 or >=300 good or expensive >=5 <500 or >=500 Good or Expensive Write a program that asks the user to enter the...

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • Could anyone please help with this Python code assignment? In this programming assignment you are to...

    Could anyone please help with this Python code assignment? In this programming assignment you are to create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The count of how many numbers are in the file. The average of the numbers. The average is the sum of the numbers divided by how many there are. The maximum value. The...

  • CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1....

    CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1. Create a program named printRandomNumbers that gets input from the user and then produces a list of random numbers. 2. Import the random module 3. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description c. Programmer's Name (You) 4. Prompt the user for the following: a. Number of random numbers required b. Lower limit of...

  • Using C++ Requirements Note: “deque” STL container is not allowed, for the simplicity for graders. Queue Queue is a firs...

    Using C++ Requirements Note: “deque” STL container is not allowed, for the simplicity for graders. Queue Queue is a first-in-first-out (FIFO) data structure. For the Queue container, we will implement a program that simulates a buffer. The simulation needs a function that randomly generate number. And the buffer simulation starts with no value in the buffer. At the start of simulation, the menu should ask user: how many rounds will be simulated. the percentage chance to put a randomly generated...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT