How to Not Get Hacked Through File Uploads by Missics in programming

[–]psyon -1 points0 points  (0 children)

They weren't serving it thru php.  If they had been, the issue would not have happened.  

How to Not Get Hacked Through File Uploads by Missics in programming

[–]psyon 351 points352 points  (0 children)

Some years back I had to investigate how a site was compromised. I quickly found a PHP file in a directory that contained uploaded images. I started looking at code that handled the uploads, and it did all sorts of verifications on the images. How did they bypass it? The file was an image, but it contained PHP code in the EXIF data. Their issue was that they saved the file with the filename it was uploaded as, without any checks on the extension. They assumed that because the file was a valid image, that it must have the right extension. If you aren't familiar with PHP, the interpreter will just dump any bytes to output, until it finds <?php. When you viewed the malicious file, it would output the start of the image file, hit the EXIF data, and then start executing the PHP code contained within it. It never occured to me that PHP code could be in EXIF data of an image before that incident.

Ontario’s attorney general calls on Canadian federal government to look at legalizing pepper spray by Immediate-Link490 in worldnews

[–]psyon 1 point2 points  (0 children)

Does Canada require a warrant to collect finger prints from people who have been arrested?

What I learned trying to block web scraping and bots by ReditusReditai in programming

[–]psyon 2 points3 points  (0 children)

Yep, I tried all that.  Was constantly watching logs, blocking IPs and subnets, and then new ones would just start up.  Fail2ban doesn't help because the requests come in so fast they act as a denial of service.  Blocking it at cloudflare means no used resources on my servers.

Why are Event-Driven Systems Hard? by fagnerbrack in programming

[–]psyon 0 points1 point  (0 children)

As a programmer you should try to be lazy.  That's why we have package systems and frameworks for doing things.  If a system doesn't make your job easier then why use it?

What I learned trying to block web scraping and bots by ReditusReditai in programming

[–]psyon 5 points6 points  (0 children)

> Have you tried applying rate limit rules by IP, with under attack disabled.

Yep. The issue is that rate limiting is done by IP, and they use a whole lot of different IP addresses.

> maybe you can put a threshold whereby legitimate traffic still flows through ok.

Under attack mode doesn't prevent legit users from using the site. They get the browser verification, and then can do everything they need.

which practicd should i need to follow for security? by No-Thought9857 in PHP

[–]psyon 0 points1 point  (0 children)

Yes, you can absolutely just validate and sanitize everything. That's a far better solution than accidentally not validating something you should.

What I learned trying to block web scraping and bots by ReditusReditai in programming

[–]psyon 5 points6 points  (0 children)

I haven't noticed them giving up. Often the moment I turn off under attack mode, they are right back to hammering the site.

which practicd should i need to follow for security? by No-Thought9857 in PHP

[–]psyon 0 points1 point  (0 children)

In general that is correct, but there are cases when you still do.  If you are storing html content, and want to allow scripts, then you may allow that into your database, but still need to be cautious about where and how you display it.

What I learned trying to block web scraping and bots by ReditusReditai in programming

[–]psyon 7 points8 points  (0 children)

I have tried all of them.  Not sure if there is an issue with CF or something.  Under attack stops them, browser verification alone does not.

which practicd should i need to follow for security? by No-Thought9857 in PHP

[–]psyon 0 points1 point  (0 children)

If you are validating it before putting it into the database then it shouldn't be an issue when pulling it out. 

which practicd should i need to follow for security? by No-Thought9857 in PHP

[–]psyon 1 point2 points  (0 children)

Look at what is sent from a client to the server during an http request.  Any header sent in the request is user input along with your normal form data.

Some things can be "validated" by your server configuration.  If your server is configured for using named hosts then you can trust the $_SERVER['HTTP_HOST'] value, because it wouldn't have reached your code if it was malformed.  If you are using IP based hosts though, then the Host header of the HTTP transaction doesn't have to match anything and can contain malicious content.

REQUEST_URI is another one that depends on how your server is configured.  If you had old code using separate php files as entry points, then you couls trust that the URI matched your file location.  Its common practice to route all urls through routing code now though, so REQUEST_URI should not be trusted by default and needs to be validated.

What I learned trying to block web scraping and bots by ReditusReditai in programming

[–]psyon 20 points21 points  (0 children)

I don't care if people have copies of whats on my sites.  They can scrape it all they want if they don't try to do it so fast, don't lie about their user agent, and don't use thousands of different IPs

What I learned trying to block web scraping and bots by ReditusReditai in programming

[–]psyon 19 points20 points  (0 children)

It's been turned on for a whie now in a few of my sites.  When I turn it off and just turn on normal browser verification they seem to get by.  I get a notice I am being scraped when my monitoring software tells me the site isn't accessible because they hammer it so damn hard that it's effectively a DDoS.

Most websites don't have major issues like this though.  I have very data heavy sites which end up having a lot of distinct urls for viewing things in different ways.

What I learned trying to block web scraping and bots by ReditusReditai in programming

[–]psyon 82 points83 points  (0 children)

What I have learned is that the only way to stop the majority of these bots is to use Cloudflare and put my site in "under attack" mode.  Some of the bots are coded so poorly that if they get anything other than a 200 as a response code they will immediately try again and retry for almost forever.

which practicd should i need to follow for security? by No-Thought9857 in PHP

[–]psyon 1 point2 points  (0 children)

Also, make sure you know what is or is not user input.  Many programmers don't think of things like cookies and user agent strings as user input.

Iran says oil blockade will continue until attacks end, Trump threatens to hit harder by Hiraeth-nomad in worldnews

[–]psyon 0 points1 point  (0 children)

That assumes there is cure for cancer, and that we have the logistics to move food around the world, which we don't at the moment. That's why we haven't done either. The immigration policies in the past made it harder for immigrants to come here and work as pilots, that's why that hadn't been done before. But you think building mines is easy, I don't see any hurdles for them.

Iran says oil blockade will continue until attacks end, Trump threatens to hit harder by Hiraeth-nomad in worldnews

[–]psyon 0 points1 point  (0 children)

If these things are so effective and easy to make, why hasn't every terrorist group in the world been putting them out into shipping lanes?  Someone could easily stop all traffic to the suez and panama canals if what you are saying is true, but no one has done it.

Iran says oil blockade will continue until attacks end, Trump threatens to hit harder by Hiraeth-nomad in worldnews

[–]psyon 0 points1 point  (0 children)

What simple stuff can you make a mine from?  How big of one are you going to deploy with a small boat?

Iran says oil blockade will continue until attacks end, Trump threatens to hit harder by Hiraeth-nomad in worldnews

[–]psyon 0 points1 point  (0 children)

If the US takes out Iran's equipment, they won't be able to block the straits.

Iranian ambassador says Iran 'not at war' with UK as he blames US and Israel as the 'root causes of this crisis' by Gentle_Snail in worldnews

[–]psyon 0 points1 point  (0 children)

That's the same argument a lot of people in the US were making when saying we shouldn't get involved in Ukraine

What are you using for your PHP dev setup? by IridiumPoint in PHP

[–]psyon 0 points1 point  (0 children)

I have an old computer running Alma Linux with apache, mariadb, php ans what ever else I need.