Srs DST: Casting From To
Srs DST: Casting From To
casting
Casting from srs to dst
#include <iostream.h>
class dst { public: int x; };
class srs
{
private: int x;
public:
srs(int a):x(a){}
operator dst() { dst d; d.x=x; return d; }
};
void main()
{
srs s(1); dst d=(dst)s; cout << d.x;
}
gives access to private data.
Using private constructors
public class Capability
{
private int capabilities;
static private int specialCapability=4;
private Capability(int c) { capabilities = c; }
public bool Test(int capnum)
{ return (capabilities & (1 <<
specialCapability) )!= 0; }
class Uid
{
private: int id;
public:
Uid(): id (0) { }
int get() { return id; }
void set(int new_id)
{
if (id == 0)
id = new_id;
else
throw new SetException();
}
};
Vulnerabilities in OOP: Virtual Methods
vulnerabilities
vtable; vptr
Countermeasures:
placing them before member variables in
memory
what if several objects are allocated in a
contiguous memory ?
Vulnerabilities in OOP: unsafe plugins
(Abadi and Fournet, 2003)
namespace ConsoleApplication1
{
abstract class Trusted
{ // full privileges
static protected String tempfile = "/tmp/tempfile";
abstract public void proceed();
static void Main()
{
BadPlugin bp = new BadPlugin();
try { bp.proceed(); }
catch (Exception e){ File.Delete(Trusted.tempfile); throw(e);}
}
}
class BadPlugin : Trusted
{ // low privileges
override public void proceed() { tempfile = "/etc/passwd"; }
}
}
Who cares about security?
Businesses do:
Feb 2000:
● Yahoo, Buy.com, Amazon.com, CNN, etc. shutdown
by massive DDoS attack. Yahoo lost more than
$1m per minute...
Aug 2000:
● Fake news report posted on internet news agency
computer - “Emulex Corporation”'s CEO resigns and
quarterly earnings adjusted to loss, not profit. Share
price drops 60% in hours ($billions!).
sandbox model - security technique is to run
applications from unsafe sources through an
isolated environment (sandbox) so that it can
be tested without any breach of privilege
affecting the original system. This isolation
can be:
a virtual machine providing validation for data
types and authorization for access to memory;
a native API controlling access to resources. In
this case, methods like
SecurityManager.checkPermission
(checkRead, checkAccept, ...)
or similar variants are called before any sensitive
operation.
What is the .NET Framework?
Microsoft’s cross-language development platform
• Execution environment / VM:
Common Language Runtime (CLR)
• Intermediate Language: MSIL (similar to bytecode)
• Class libraries: “The Framework” (FCL/BCL)
• Language compilers (+30, MS & 3rd party)
• Development tools: Visual Studio.NET
textBox1.Text+="Assembly Evidence:";
enumerator = ev.GetAssemblyEnumerator();
while (enumerator.MoveNext())
{
textBox1.Text+=enumerator.Current + "\r\n";
}
Memory management in a
GC’ed environment
Usually, developers don’t have to explicitly
manage memory in a GC’d environment, but
that’s not quite true: they have to worry
about manually clearing sensitive data as
soon as they are done with it