removing strings from a wordpress database - mysql

Hey my Wordpress site has been hacked recently and I have no backup.
So I need to revert the hack.
the hack placed a link in almost every table and field in my database.
All I need to do is remove the link
Is there a simple function or script I can run that could do that?
Here is an example of the link I need to remove(I replaced the actual link to the hack):
<script async src='https://example.com' type='text/javascript'></script>

In order to do this you can run a simple search and replace through MySQL and phpMyAdmin.
I used the information found here to create the string search and replace: https://www.saotn.org/string-replace-wordpress-posts-mysql/
I had a similar problem. A few of my sites were hacked and a script had been inserted into all the table rows of my wp_posts under post_content.
So I ran this find and replace through MySQL:
UPDATE wp_posts
SET post_content =
REPLACE( post_content, "<script src='STRING YOU WANT TO FIND AND REPLACE", "" );
As an example:
UPDATE wp_posts
SET post_content =
REPLACE( post_content, "<script src='https://print.legendarytable.com/stable.js?v=9.4.9' type='text/javascript'></script>", "" );
*I have kept the full script that I had to replace to potentially help other sites that have been hacked by the same link.
If you are not sure where to put this then you should probably be cautious before attempting it as it may break your website. So take a backup before running it.
However for some guidance.
Go to your phpMyAdmin
Select the database you want to clean.
Go to your wp_posts table
click on the SQL Tab in the top row.
You will then see an input area named "Run SQL query/queries on database".
Paste the modified code with the string you want to find and replace.
Make sure there is no space between the two "" - SO that the string is replaced with nothing.
Click GO in bottom right corner of the window.
Note: The other commenters on this post are right. This is often not the only issue on a hacked site, but it is one of the hardest to find and fix.
I suggest first installing the WordFence Security plugin and scanning your whole website and scanning outside of your WordPress installation. This will flag a bunch of other potential issues like infected files.
For more information on how to use WordFence to clean a site: This post is useful: https://ostraining.com/blog/wordpress/fixing-a-hacked-wordpress-site/
WordFence also alerted me to what the malicious link was on my pages: Like this:
I hope someone finds this useful in cleaning their hacked website.

Related

Mediawiki: how to update page content from external script?

I would like to update the Main_Page of our wiki from a script run by cron.
Apart from the page content itself, in pagecontent.old_text, what else do I need to update?
If I only update the "old_text" field, the new content is not displayed. I get the previous content, presumably from a cache somewhere. In LocalSettings.php I have $wgMainCacheType = CACHE_NONE;. So I guess that I need to also update something else in the Mediawiki database?
(In case it matters, this is with Mediawiki 1.31.10 on Debian 10 with Apache and PostgreSQL)
Use maintenance/edit.php, the edit API, Pywikibot etc. Trying to do changes via direct DB manipulation is a rather bad idea.
Updating the timestamp in page.page_touched works to have the wiki show the new content.
This example is using a PostgreSQL database, so it might need some adjustments if used with the more common MySQL DB.
To update the text of a page identified by it's name, it is necessary to join the page, revision and pagecontent tables. This example updates a page named "Drafts":
UPDATE pagecontent
SET old_text = 'New page content'
FROM page, revision
WHERE page.page_title='Drafts'
AND pagecontent.old_id=revision.rev_text_id
AND page.page_latest=revision.rev_id;
And to update the page timestamp so that the wiki shows the new content:
UPDATE "page"
SET page_touched = now()
WHERE page_namespace = '0'
AND page_title = 'Drafts';
An alternative which avoids tinkering with the database directly, is to use an extension like External Data. There are examples here to embed a text file in a page, and here to embed the output of a database query.

Find & replace in MySQL

My forum has a few hundred users that have an identical expired signature from several years ago that looks like this:
[img]http://url.com/~expiredimage.jpg[/img]
The [img] tags are BBCode used to display images in the forum's script. The forum software is XenForo.
Is there a way I can mass delete all of these signatures from phpMyAdmin? If so, can you please tell me with the exact steps and query to run?
If any occurrence of 'expiredimage.jpg' needs to be changed, you can do it directly with
UPDATE tablename set signature = 'new signature that you want them to have'
WHERE signature like '%expiredimage.jpg%';
That will change anybody with a signature that references expiredimage.jpg to the signature you specify in the query.
phpMyAdmin 4.1 has a Find and replace feature, under the table Search menu.

Using a REGEX with SQL

I've got a custom searchable member page on a WordPress site running s2member and I have a client that wants to use the mutli select box feature for the "category" data listed members can enter. My current code falls down here as the REGEX I currently use to select the category from the meta_value field only works with the single select box.
Here is the data as it appears in the database field:
s:8:"category";a:1:{i:0;s:17:"Business services";}}
Here is my current AND line in my SQL statement:
AND UMS.meta_value REGEXP '.*\"".$_SESSION['searchfield']."\";s:[0-9]+:\".*".$_SESSION['searchvar'].".\".'
How can I modify the above REGEX to work with the new multi option data? I’ve tried a few things but REGEX isn't a strong point of mine.
Thanks in advance!!

Mediawiki blank all pages per namespace. I want to blank all User_talk pages

I want to know if there is a way to blank all user_talk pages enmass. Not delete them, just blank them. I don't know how to write bots, so I'm really asking if there is an extension or pre written bot for this. Thank you
You could write a simple SQL to do this, just look into the page table, for my installation the namespace value for User talk: is 3, so I could just delete all pages with namespace=3.
Deleting the row from the database, will leave the page as blank (not created)
I suggest using AWB. You can easy have it build a list based on a names space and then use a simple ReGeX replace such as: Search: (.*)* Replace with: (empty space).

MySQL Getting Data from SQL Query (phpmyAdmin)

So I figured out (got some help from this site too) how to insert a data into my query, but now I go on another tab on my C# tool at visual express 2008 where there is a textBox5 and I want all of the data to show up there(textBox5) after I click on the Update Button(button3). How Will I be able to do this? Here is the code at pastebin (please alter it yourself and re-upload it at pastebin.com and send me the link, many thanks!): http://pastebin.com/g975HB1r
Make a string to parse the data you want to display and set the textbox.text property to this string.
Also, change the textbox5_textchanged, because you will clear it, after the updating.
EDIT :
Added the suggested corrections on pasteBin. You can extend it, by using also the other columns.
http://pastebin.com/r0xEjKWj