A picture got my PostgreSQL database to start mining Monero
imperva.com
imperva.com
- Gain access to the database itself
- And the Postgres database should be vulnerable to various remote code execution
- Once they're able to execute code remotely, they then download an image which has binary data tacked onto it
- They then parse out the executable part of the image using dd
- Then they're able to execute and mine away
While an interesting read the shortest takeaway is:
1. Don't leave your Postgres open to the public internet and
2. Ensure to upgrade when security releases come out.
If you're unsure if the version your on has security patches available or other reasons to upgrade consider checking out https://why-upgrade.depesz.com/
Edit: Looks like the user that gained access had ability to execute pl/c. Which has to run as superuser. You won't find things like pl/c, pl/python generally supported on most Postgres services like Heroku, RDS, Citus because of just this reason. So in this case database access with pl/c was enabled, suspect could have been done equally via other vectors (once database access was achieved).
This means that real attackers are attempting right now.
So, the takeaway would be to control, which functionality is needed and which not, then to take action accordingly.
Secondly, things like lo_export() should be disabled by default.
It does require privileges.
> Secondly, things like lo_export() should be disabled by default.
It's superuser only.
Your databases should have multiple users configured with limited roles. Nothing web-facing should have a user with the ability to create a function. A SELECT-only user is a good start.
you need to do better than that, since attacks within the firewall can occur as well, and this is probably a more common vector for corporate espionage these days. A compromised laptop can get a wide open remote exploit onto a companies' production environment if the database itself is open within the firewall.
4. Don't let your DB host make outbound connections (iptables/ip6tables)
Which can also be prevented with SELinux
It can't be exploited if the security "best practices" are used. But I've come across situations where people were using "sa" as the account for production SQL Server connections because they just didn't know any better. Things are much better in the linux/bsd world where there is generally more competence and people tend to know what they are doing.
Having said that, things are getting better. IT/developers are much more mindful of security concerns today than 10 years ago.
Wow. IMO buried lede. That is... very impressive.
your head
[0]: http://www.zdnet.com/article/mongodb-ransacking-starts-again...
I ask this because people expose web-apps on the Internet publicly too and an SQL injection vulnerability on the web-app would also be equally catastrophic.
I guess exposing web-apps on the Internet is a risk we need to accept because it has to be available to users of the Internet. But we should not expose anything else that we don't need to? Is that the reason why exposing databases publicly is considered best practice.
I would like to know what experienced professionals think about this.
If the database itself is publicly exposed, even if a read only connection with access to an empty table is provided an attacker could simply max out the connection pool to kill your application. If a vulnerability was published or a password with more access was available they can not only access all of your data but they can corrupt it and/or delete it.
SQL injection has been pretty trivial to stop for a couple of decades now.
Yes. Why would you ever need public logins from the open internet to your production database? Even if you need to ability to log in from a random computer, there are better ways, like requiring the use of a vpn so logins are always coming from a white listed ip.
The database OTOH represents an entire programming shell, e.g. extremely fine-grained and in many cases linked directly to the underlying system as was shown in this article - additionally, the number of entrypoints is undefined. If you somehow were convinced that you've locked down every single function of your database from attack, the next day you upgrade the database to a new version and it can very well expose new functions that are again exposed.
It’s really hard to move fast and stay secure. You have to nail so many things and you’re either running out of money or running out of time 99% of the time.
Would the payload still be there if the image was rebuilt with Imagemagick?
Don't allow superuser connections from outside of your network.
Run Postgres in a limited user. Something that can't access any file or execute any command (like wget) it doesn't need, can't do chmod +x. Can't run a shell. Don't know if postgres needs that.
And I don't think it's a reasonable idea to not have a superuser at all. But you can have it password less and only accessible from the local machine and a specific account (eg root).
For image hosting services it is required to process images anyway - for example to strip EXIF GPS data. It looks like imagemagick can't really do it for JPEGs: https://stackoverflow.com/questions/2654281/how-to-remove-ex...
The real solution is not to go around making DBAs' lives harder by disabling all this stuff. The real solution is to not give attackers on the internet superuser access on your database!!! Why is the database exposed to the public internet to begin with?
It takes someone with astute observation skills to see this.
That hasn't changed, folks. If someone on the Internet can talk to your Postgres database, you are Doing It Wrong.
Who has to run the Postgres database?
In what kind of way does it has to be accessed to get this happening?
Are we talking about web apps that use Postgres on the back end and run arbitrary queries?
Are we talking about people who somehow extract the Postgres database username and password and it has admin permissions?
I wasn't sure what's happening.
- make it easy to host it on a public, reputable, unblocked web site;
- have a format AV detect less often.
But how would an unsuspecting user run the executable? Perhaps I missed this, but is there some image viewer or browser that runs the trailing bytes of images?
Is there a name for these kind of contingent exploits? If step 1 is get root/execute code, it it reduces the risk of the exploit.
Still valuable to know about, but not that much if you can execute code on a server.
0. https://github.com/nixawk/pentest-wiki/blob/master/2.Vulnera... 1. https://www.rapid7.com/db/modules/exploit/linux/postgres/pos...
I am fairly sure that this could have been prevented by SELinux.
* AWS RDS + Heroku and not knowing better
* Sharing a database with a customer
There are a lot of reasons. Some are ok, some are not
The only reason I can see is for honeypot.
"Error establishing a database connection"
From / credit to: https://news.ycombinator.com/item?id=16618030
Cryptocurrencies are run on, by, and for crime. It's immoral to participate in cryptocurrencies. You wouldn't be a member of a club that had people like this owning the club house and everyone on the board, but due to pure greed and wilful ignorance people keep "investing" in this organized crime.
Shame on you all.
This was one currency and bad behavior used to obtain it doesn't even reflect on that.
Investors ignoring or rationalising all the bad because of their greed is, in my opinion, disgusting.