.NET DECK Flashcards
Four phases of web application attacks
Recon, Mapping, Discovery, Expoit
Most attacks are ________ specific to .NET; they are found in….
NOT specific to .NET, and don’t need any knowledge of it to exploit it. Found generically in HTTP, AJAX, JS, XML, SQL.
Four main things that can be attacked on a page
Verbs. (Using Gets vs. Posts, etc)
URL
Headers (User agents, referrers, cookies)
Content in the page (Page forms, JS, CSS, etc)
Places where data validation needs to happen
Between every layer of the model. From application to middleware to back end DB, and from DB back to the application.
Should be parameterized and encoded, validated w/whitelists.
Before performing data validation, it’s important to identify every _________ in your system diagram/threat model.
trust boundary
How should validation be performed?
- At every layer/tier.
- By senior, experienced developers
- Consistently, simply, and in a way that it can be audited.
What are some validation techniques?
Indirect Selection (moving a string variable to an integer, etc) Blacklists Whitelists (better) Parse CMD Regex
A WAF is a big, shiny, _________.
blacklist. It blocks known bad characters. (better than nothing)
Whitelists
Validation construct that allows only known good, established chars. Better than blacklists.
Indirect Selection
Change input adding fields to drop downs, associate strings as integers so they can be parsed and don’t allow free form, don’t directly access objects.
By storing a string with a number representation, it means that validation just needs to be an integer check.
Validation Paradigm
How to validate:
- White list input
- Constrain/reject in that sample
- Assign input to a local variable so it can be referenced w/o touching the value. (validate the input, assign the original value to CleanString, then only reference CleanString)
TryParse()
Built in .NET/C# method. Easy way to take invalid strings and parse them into corresponding type w/o generating an exception. Easy way to constrain places where users enter input.
Why use TryParse()
Common way to convert strings into a usable integer; lots of classes are set up this way. Easy way to constrain user input.
What happens when TryParse() has an error
Rather than throwing an exception, it will return a converted number or a zero.
How to test regex
Deconstruct them and run them through a tool, such as the regex coach/the Regulator/Expresso
what is (^\d{3}-\d{2}-\d{4}$)
the SSN regex
What is (\p{Lu}) and (\p{LI})
Regex to match one Unicode uppercase character and lowercase character.
What is (\w) or \d)
Regex for matching a word character or a digit
How do data annotations work?
Data annotations are patterns (in the form of attributes) for standard input validation in MVC. They include things like “Credit Card” or “Phone” or “URL” that validate a specific set of rules on a a field.
Annotations are decorated on the method to enforce the behavior.
How do errors get added to ModelState, so that that it can be valid or invalid?
Model binding automatically adds errors to the state when it receives POST form data. If any POST data has an error in validation, it automatically adds it. You can also manually have code add an error to the state.
For example, you can have an if/else block where the “else” throws an error and adds it to the model state, for custom errors.
When does Model State binding happen?
When POST form data is received, it “binds” the value pairs to the model, with any errors its received.
What is under-posting and over-posting?
When an attacker adds post value/pair fields that aren’t there in the standard request, or deletes ones that are.
How to prevent under-posting and under-posting
ViewModel design.
Create a ViewModel with a 1 to 1 mapping between the specific view and a model. Model is then mapped to an entity object by the controller.
.NET custom annotations
.NET has options for annotation (attribute) driven validation. You can make your own, add it to the model. (Like with SANS.Appsec.Name annotation referencing a common validation custom validation scheme
Can create your own ModelState errors to check against the IsValid library.