Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: crazy_rabbit on February 04, 2013, 11:18:23 PM



Title: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: crazy_rabbit on February 04, 2013, 11:18:23 PM
So I'm working on a project that will hold bitcoins and of course, security is the most obvious risk/danger.

On advice of the developer we have a specially compiled version of bitcoind (unnecessary RPC calls have been removed, as well as calls that pose a security risk).

Bitcoind runs under a separate user than the php script. SSH/ftp into the server is only possible with keyfiles.

All mysql calls are escaped so injection should (hopefully) be covered.

A cold wallet is being implemented so the majority of funds are off-site.

What other steps should I be keeping in mind? After some advice from a friend I'm worried as well about somehow the database being compromised in some slight way as to affect imperceptible shifts in balances that I would be unable to detect.

I toyed with the idea of every database entry having a hash generated from all the data and the hash being periodically verified against the database to check for manipulation. But is this realistic?

Anyone have any more ideas? Thank you


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: hardcore-fs on February 05, 2013, 12:17:06 AM
With the admin tool you can make any changes you want to the database and it cannot be detected, also corruption
better to encrypt certain fields in the database


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: CIYAM on February 05, 2013, 12:32:32 AM
Agreed that if you are storing information that is sensitive (such as email addresses or other more personal information) then it should be encrypted.

If you need to *index* any such columns then this will make things trickier (although you could create another column for indexing purposes that contains the first x characters provided that isn't going to be a problem application-wise).


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: crazy_rabbit on February 05, 2013, 09:14:28 AM
Sensitive information, like email is encrypted and salted. The admin tools are locked to IP addresses as well, although their powers are limited in scope. Users can choose to use Google Authenticator as well.

Anything else? I'm sure there must be lots of things I'm overlooking!


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: K1773R on February 05, 2013, 09:18:58 AM
Sensitive information, like email is encrypted and salted. The admin tools are locked to IP addresses as well, although their powers are limited in scope. Users can choose to use Google Authenticator as well.

Anything else? I'm sure there must be lots of things I'm overlooking!
encrypted + salted = ?
need more input ;)

just a basic rule: dont use fancy librarys, or libs who have/had alot of vulnerabilitys


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: davout on February 05, 2013, 09:36:10 AM
So I'm working on a project that will hold bitcoins and of course, security is the most obvious risk/danger.

On advice of the developer we have a specially compiled version of bitcoind (unnecessary RPC calls have been removed, as well as calls that pose a security risk).
That's actually terrible advice, that means you need to maintain your separate fork of bitcoin which will make it much less straightforward to apply patches and security fixes as they come. Choose a strong password for the RPC calls, listen only on the local interface and add some iptables rules on top of it just to be sure. MUCH more secure. If you keep the "send" calls disabling other calls is pointless. If you don't keep them you might as well run a wallet such as armory.

Bitcoind runs under a separate user than the php script. SSH/ftp into the server is only possible with keyfiles.
If you have proper passphrases on the private keys it is a good idea.

All mysql calls are escaped so injection should (hopefully) be covered.
Don't reinvent the wheel, use a framework or a lib that does that for you.

A cold wallet is being implemented so the majority of funds are off-site.
Good.

I toyed with the idea of every database entry having a hash generated from all the data and the hash being periodically verified against the database to check for manipulation. But is this realistic?
No, because if someone can mess with the DB they can mess with the hash.
If you really want to go down that road keep backups and run periodic data comparisons to see if historical data has been altered.

Sensitive information, like email is encrypted and salted. The admin tools are locked to IP addresses as well, although their powers are limited in scope. Users can choose to use Google Authenticator as well.
Encryption is absolutely pointless if you keep the decryption keys on the server.

Agreed that if you are storing information that is sensitive (such as email addresses or other more personal information) then it should be encrypted.

If you need to *index* any such columns then this will make things trickier (although you could create another column for indexing purposes that contains the first x characters provided that isn't going to be a problem application-wise).
That doesn't make sense at all, if you need to query on a column chances are the application needs to be able to decrypt it at will for display or other purposes, meaning you'd have to have the keys on the server which defeats the whole thing.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: CIYAM on February 05, 2013, 11:25:01 AM
That doesn't make sense at all, if you need to query on a column chances are the application needs to be able to decrypt it at will for display or other purposes, meaning you'd have to have the keys on the server which defeats the whole thing.

Wrong - you may not have even heard of a thing called a "transient" being a Rails user (so don't make corrections about stuff that you don't understand).

And - yes good luck in finding the keys in my compiled code (which only *part* is - something script kiddies just can't do now is it).


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: davout on February 05, 2013, 11:42:20 AM
Wrong - you may not have even heard of a thing called a "transient" being a Rails user (so don't make corrections about stuff that you don't understand).
What about transient objects ? (that exist in Rails, and in any framework that uses an ORM for the matter).
What makes you think I don't know anything else than Rails ?

And - yes good luck in finding the keys in my compiled code (which only *part* is - something script kiddies just can't do now is it).
Assuming OP is using a compiled language.

Assuming it's not trivial to decompile any kind of language to extract constants or do a memory dump for anyone who has the slightest clue about what they are doing.

Your security protects you against script-kiddies? Great! Now let's go back to real security that works with everyone.

Making it slightly harder to get the keys doesn't make a flawed security model less flawed.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: CIYAM on February 05, 2013, 11:49:41 AM
Your security protects you against script-kiddies? Great! Now let's go back to real security that works with everyone.

Making it slightly harder to get the keys doesn't make a flawed security model less flawed.

Please Davout - go get someone to hack my site and then we can talk about security models.

There is *nothing* flawed apart from your (once again) bad behaviour in this forum (I suggest *growing up* and stop trying to be such a smart ass for starters).


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: davout on February 05, 2013, 12:03:04 PM
Please Davout - go get someone to hack my site and then we can talk about security models.
Keeping a decryption key on the same server that holds encrypted data is a bad security model.
This is factual, you can't have your cake and eat it too, security is about tradeoffs, if you want security you have to give up some convenience.
If someone tells you you can get a 7% weekly interest on your deposit he's probably a scammer.
If someone tells you you can encrypt data in the DB but automatically decrypt it at will he doesn't understand security. Slam dunk case of security-by-obscurity.

The is *nothing* flawed apart from your (once again) bad behaviour in this forum (I suggest *growing up* and stop trying to be such a smart ass for starters).
This is not about your little ego, it's about facts.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: CIYAM on February 05, 2013, 12:10:11 PM
This is not about your little ego, it's about facts.

Hmm... my little ego - well let's just leave it at that (as yours is clearly *bigger*).

I was doing security since before you were even born but of course you *must* be better than I.

:D


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: davout on February 05, 2013, 12:16:03 PM
I was doing security since before you were even born but of course you *must* be better than I.
Maybe it's time to brush up grandpa.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: CIYAM on February 05, 2013, 12:20:00 PM
I was doing security since before you were even born but of course you *must* be better than I.
Maybe it's time to brush up grandpa.

Quoted for the sake of it (this is how a *professional* business guys show their stuff these days).

Also will use the *ignore* feature for the very first time (congrats - couldn't have used it on a more deserving member).


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: crazy_rabbit on February 05, 2013, 02:39:50 PM
Hey guys! Break it up!  :o

Honestly both of you are giving me really good advice to think about. Any practical ideas to keep the sever where the code is hosted safe? I presumably could get a server running that hosted the bitcoind dameon and listened only to the ip of the main server. But how to ensure someone can't get into my server where the app code is hosted?



Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: davout on February 05, 2013, 04:11:24 PM
Hey guys! Break it up!  :o

Honestly both of you are giving me really good advice to think about. Any practical ideas to keep the sever where the code is hosted safe? I presumably could get a server running that hosted the bitcoind dameon and listened only to the ip of the main server. But how to ensure someone can't get into my server where the app code is hosted?
You know, people write books about this subject. I suggest buying one.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: DannyHamilton on February 05, 2013, 04:45:30 PM
You know, people write books about this subject. I suggest buying one.
I thought the internet was created so that we wouldn't need books any longer?


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: davout on February 05, 2013, 04:53:29 PM
I thought the internet was created so that we wouldn't need books any longer?
Well, e-books would qualify as books in my view.
I guess what I'm trying to say is that if the OP is asking such general questions on an internet forum, it can mean that he simply is not ready to undertake the task of thoroughly securing his server.
So my general advice would be that he document himself about the general principles, the different security layers, understand all the trade-offs and design choices that impact security and come back with a solid plan.

The OP seems to have interesting ideas (on which I already commented) but a serious lack of experience. Lacking experience is allright as long as you know it and have the brains to think for yourself.

Two general security principles :
 - You can't have your cake and eat it too, there is *always* a trade-off between security and convenience, no exceptions.
 - Don't code security-related stuff yourself, someone has probably already done it, and done it better than you. Use libraries as much as possible, not fancy ones, but mature ones. Don't hand-escape SQL, don't hash passwords yourself, etc. You get the idea.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: crazy_rabbit on February 05, 2013, 11:22:05 PM
I thought the internet was created so that we wouldn't need books any longer?
Well, e-books would qualify as books in my view.
I guess what I'm trying to say is that if the OP is asking such general questions on an internet forum, it can mean that he simply is not ready to undertake the task of thoroughly securing his server.
So my general advice would be that he document himself about the general principles, the different security layers, understand all the trade-offs and design choices that impact security and come back with a solid plan.

The OP seems to have interesting ideas (on which I already commented) but a serious lack of experience. Lacking experience is allright as long as you know it and have the brains to think for yourself.

Two general security principles :
 - You can't have your cake and eat it too, there is *always* a trade-off between security and convenience, no exceptions.
 - Don't code security-related stuff yourself, someone has probably already done it, and done it better than you. Use libraries as much as possible, not fancy ones, but mature ones. Don't hand-escape SQL, don't hash passwords yourself, etc. You get the idea.

A book is a very good idea. That said- there are tons of them. Any you could recommend in particular? If not, I'm sure amazon will help, but that said- I was thinking there might be others here who went through the same growing pains. :-)


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: davout on February 05, 2013, 11:31:31 PM
A book is a very good idea. That said- there are tons of them. Any you could recommend in particular? If not, I'm sure amazon will help, but that said- I was thinking there might be others here who went through the same growing pains. :-)

I don't really have a specific book in mind, but if I see one I'll be sure to update this thread.
Part of the "growing pains" you mention is "growing", and growing takes time and patience :)

I wish you luck !


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: BCB on February 05, 2013, 11:57:43 PM
Close all unnecessary ports.

Only open ssh to admin's ip.

Don't run a mail server, irc bouncer or chat client on the same server.

If you can or if you can plan to scale run  Bitcoind, Web Server and mysql on separate servers.

Replicate mysql to a 4th server. 

Run Hourly encrypted backup on the Rep Server
Run Daily Encrypted back upon on the Main Mysql server
Save encrypted backup off-site daily.
Use an HSM to store and manage all private keys.

Plan for complete failure and run monthly complete restore runs only from back up.

implement fail over  in co-located data centers.



Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: davout on February 06, 2013, 12:09:38 AM
Close all unnecessary ports.

Only open ssh to admin's ip.

[...]

Plan for complete failure and run monthly complete restore runs only from back up.

implement fail over  in co-located data centers.
Slightly overkill for the OP if you ask me.
While you're at it you might want to add that everything should be hosted in a nuclear bunker. On Mars.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: K1773R on February 06, 2013, 12:37:54 AM
Close all unnecessary ports.

Only open ssh to admin's ip.

[...]

Plan for complete failure and run monthly complete restore runs only from back up.

implement fail over  in co-located data centers.
Slightly overkill for the OP if you ask me.
While you're at it you might want to add that everything should be hosted in a nuclear bunker. On Mars.
so you have a service for hosting a server on mars? il take 1


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: BCB on February 06, 2013, 12:40:43 AM
yes this is extreme. Additional layers of security can be added with growth of value.

But we've seen it all in bitcoin.

Compromised hosts

exposed public keys

unpatched zero day exploit

trojans

disappearing data that was not backed up.

insider fraud.

If you are dealing with anything of value exposed though an http interface you are vulnerable.

You can never be too safe.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: madmadmax on February 09, 2013, 02:21:27 PM
So I'm working on a project that will hold bitcoins and of course, security is the most obvious risk/danger.

On advice of the developer we have a specially compiled version of bitcoind (unnecessary RPC calls have been removed, as well as calls that pose a security risk).

Bitcoind runs under a separate user than the php script. SSH/ftp into the server is only possible with keyfiles.

All mysql calls are escaped so injection should (hopefully) be covered.

A cold wallet is being implemented so the majority of funds are off-site.

What other steps should I be keeping in mind? After some advice from a friend I'm worried as well about somehow the database being compromised in some slight way as to affect imperceptible shifts in balances that I would be unable to detect.

I toyed with the idea of every database entry having a hash generated from all the data and the hash being periodically verified against the database to check for manipulation. But is this realistic?

Anyone have any more ideas? Thank you

I am surprised that such an engine hasn't been developed for commercial websites yet...


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: Scrat Acorns on February 09, 2013, 02:47:34 PM
All mysql calls are escaped so injection should (hopefully) be covered.

I'd make a habit of using prepared statements exclusively. No handcrafted SQL queries. All your parameters are sent as binary (or escaped automatically in some libs) and there is no need to escape. If you handcraft SQL queries there's a small chance you'll forget to escape something.


Agreed that if you are storing information that is sensitive (such as email addresses or other more personal information) then it should be encrypted.

This makes zero sense if the decryption key is stored on the same server.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: crazy_rabbit on February 10, 2013, 06:27:38 PM
What do people think about this service:

http://www.dome9.com/

If I am hosting on Amazon Ec2, they can use the API to shut off all the ports all the time, except for when you plan to login. It seems like a nice solution to shut down any open ports, additionally as I have a developer working with me, it allows me to at a later point keep an eye on when they are on the server as well, no?



Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: crazy_rabbit on February 10, 2013, 06:52:58 PM
What do people think about this service:

http://www.dome9.com/

If I am hosting on Amazon Ec2, they can use the API to shut off all the ports all the time, except for when you plan to login. It seems like a nice solution to shut down any open ports, additionally as I have a developer working with me, it allows me to at a later point keep an eye on when they are on the server as well, no?

That is over kill for a bitcoin project, you should close the ports yourself, but 22,80,443 (if you have ssl) also if your worried about logins use ssh keys to login then you can easily remove them and that user could never come in or brute force your password. Why would you need to know when they log on to the server?

Well although I trust my developer, I might in the future have additional developers- or even the developer could be compromised in some way I can't know. It seems to make more sense to say, okay can we do this? I'll open the server for this day for updates/fixes, and then have it close again after. I don't have to wonder if the developer/s log back in at a different time after the fix has been done. I know I can close things myself, but I'm a novice. I'd rather know I haven't overlooked something.


Title: Re: Best Security Practicies for a Novice: mySQL/Bitcoin Client
Post by: BCB on February 10, 2013, 06:54:50 PM
What do people think about this service:

http://www.dome9.com/

If I am hosting on Amazon Ec2, they can use the API to shut off all the ports all the time, except for when you plan to login. It seems like a nice solution to shut down any open ports, additionally as I have a developer working with me, it allows me to at a later point keep an eye on when they are on the server as well, no?



crazy rabbit.  Great option.  Shut down all your ports except 80 and 443 and only allow access to 22 from the single ip or ips that need access.

can't get any tighter then that.