Cloud Computing
Cloud Computing
Windows will free all memory allocated by the application on process termination, so
short-running applications will not affect overall system performance significantly.
However, leaks in long-running processes like services or even Explorer plug-ins can
greatly impact system reliability and might force the user to reboot Windows in order
to make the system usable again.
Applications can allocate memory on their behalf by multiple means. Each type of
allocation can result in a leak if not freed after use. Here are some examples of
common allocation patterns:
Best Practices
Monitoring the resource consumption of your application over time is the first step
in detecting and diagnosing memory leaks. Use Windows Task Manager and add the
following columns: "Commit Size", "Handles", "User Objects", and "GDI Objects". This
will allow you to establish a baseline for your application and monitor resource usage
over time.
The following Microsoft tools provide more-detailed information and can help to
detect and diagnose leaks for the various allocation types in your application:
Certain coding and design practices can limit the number of leaks in your code.
Use smart pointers in C++ code both for heap allocations as well as for
Win32 resources like kernel HANDLEs. The C++ Standard library
provides the auto_ptr class for heap allocations. For other allocation
types you will need to write your own classes. The ATL library provides a
rich set of classes for automatic resource management for both heap
objects and kernel handles
Use compiler intrinsic features like _com_ptr_t to encapsulate your COM
interface pointers into "smart pointers" and assist with reference
counting. There are similar classes for other COM data
types: _bstr_t and _variant_t
Monitor your .NET code unusual memory usage. Managed code is not
immune to memory leaks. See "Tracking down managed memory
leaks" on how to find GC leaks
Be aware of leak patterns in web client-side code. Circular references
between COM objects and scripting engines like JScript can cause large
leaks in web applications. "Understanding and Solving Internet Explorer
Leak Patterns" has more information on these kinds of leaks. You can use
the JavaScript Memory Leak Detector to debug memory leaks in your
code. While Windows Internet Explorer 8, which is shipping with
Windows 7, mitigates most of these issues, older browsers are still
vulnerable to these bugs
Avoid using multiple exit paths from a function. Allocations assigned to
variables at function scope should be freed in one particular block at the
end of the function
Do not use exceptions in your code without freeing all local variables in
functions. If you use native exceptions, free all your allocations inside the
__finally block. If you use C++ exceptions, all your heap and handle
allocations need to be wrapped in smart pointers
Do not discard or reinitialize a PROPVARIANT object without calling
the PropVariantClear function
Code Analysis Basics
Before we go on, there are a few concepts that you should understand: “sources”,
“sinks”, and “data flow”. In code analysis speak, a “source” is the code that allows
a vulnerability to happen. Whereas a “sink” is where the vulnerability
actually happens.
Take command injection vulnerabilities, for example. A “source” in this case could
be a function that takes in user input. Whereas the “sink” would be functions that
execute system commands. If the untrusted user input can get from “source” to
“sink” without proper sanitization or validation, there is a command injection
vulnerability. Many common vulnerabilities can be identified by tracking this “data
flow” from appropriate sources to corresponding sinks.
Quick Start Hunting
If you are short on time, focusing on a few issues can help you discover the most
common and severe issues.
Start by searching for strings, keywords, and code patterns known to be indicators
for vulnerabilities or misconfiguration. For example, hardcoded credentials such as
API keys, encryption keys, and database passwords can be discovered by grepping
for keywords such as “key”, “secret”, “password”, or a regex search for hex or
base64 strings. Don’t forget to search in your git history for these strings as well.
Unchecked use of dangerous functions and outdated dependencies are also a huge
source of bugs. Grep for dangerous functions and see if they are reachable by user-
controlled data. For example, you can search for strings like and “system()” and
“eval()” for potential command injections. Search through your dependencies to
see if any of them are outdated.
Digging Deeper
You can complement the above strategy with a more extensive source code review
if you have time.
Focus on areas of code that deal with user input. User input locations such as HTTP
request parameters, HTTP headers, HTTP request paths, database entries, file
reads, and file uploads provide the entry points for attackers to exploit the
application’s vulnerabilities. Tracing data flow from these functions to
corresponding sinks can help you find common vulnerabilities such as stored-XSS,
SQL injections, shell uploads, and XXEs.
Then, review code that performs critical functionalities in the application. This
includes code that deals with authorization, authentication, and other logic critical
to business functions. Look at the protection mechanisms implemented and see if
you can bypass them. At the same time, check how business and user data are
being transported. Is sensitive information transported and stored safely?
Finally, look out for configuration issues specific to your application. Make sure
that your application is using secure settings according to best practices.
From there, go to “Add App” on the top right, and select “Public and
Private repos”.
After you authorize Shiftleft to access your Github repositories, and click on “Click
to see a list of your repositories”, you should see a list of your repos available for
analysis. If you choose to analyse one of your Github repos, all you have to do is
click on it and ShiftLeft will automatically import it for analysis.
For now, we will be using a built-in demo app. So go to “Java > Demo”, and click
on “Next”.
You should now see a new application on your dashboard! ShiftLeft is working hard
to find vulnerabilities in the application.
CONCLUSION
Data leakage is a silent type of threat. Your employee
as an insider can intentionally or accidentally leak
sensitive information. This sensitive information can
be electronically distributed via e-mail, Web sites,
FTP, instant messaging, spread sheets, databases, and
any other electronic means available – all without
your knowledge. To assess the risk of distributing
data two things are important, where first one is data
allocation strategy that helps to distribute the tuples
among customers with minimum overlap and second
one is calculating guilt probability which is based don
overlapping of his data set with the leaked data set.