Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Published Rules - thanh.wp-sqli-tainted #3320

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions thanh/wp-sqli-tainted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
function unLinklandingPage() {
$nonce = isset($_REQUEST['nonce']) ? $_REQUEST['nonce'] : '';
if (!current_user_can('edit_pages') || !wp_verify_nonce($nonce, 'aweber_unlink_page')) {
wp_send_json_error('Unauthorized', 403);
}

$post_id = $_POST['post_id'];
$landing_page_id = $_POST['landing_page_id'];

$links = get_option('aweber_landing_page_links');
if (isset($links[$landing_page_id])) {
# Get post content before linking to AWeber Landing Pages.
$previous_post = $this->getPreviousPostContent($post_id);
if (empty($previous_post)) {
$post_data = array(
'post_content' => '<div><h3 class="aweber-page-not-reverted">
The customer page could not be reverted</h3></div>',
);
} else {
$title = preg_replace_callback("/\([^)]+\)/",
array($this, "validISO8601Date"), $previous_post['post_title']);
$post_data = array(
'post_author' => $previous_post['post_author'],
'post_content' => $previous_post['post_content'],
'page_template' => $previous_post['page_template'],
'post_title' => $title,
'post_excerpt' => $previous_post['post_excerpt'],
'comment_status'=> $previous_post['comment_status'],
'ping_status' => $previous_post['ping_status'],
'post_password' => $previous_post['post_password'],
'to_ping' => $previous_post['to_ping'],
'pinged' => $previous_post['pinged'],
'post_content_filtered' => $previous_post['post_content_filtered'],
'post_parent' => $previous_post['post_parent'],
'menu_order' => $previous_post['menu_order'],
'post_mime_type'=> $previous_post['post_mime_type'],
'comment_count' => $previous_post['comment_count']
);
}
$post_data['ID'] = $post_id;
$response = $this->updatePageData($landing_page_id, $post_data);
if ($response['status'] == 'success') {
unset($links[$landing_page_id]);
update_option('aweber_landing_page_links', $links);
}
}
echo json_encode($response);
$this->_end_response();
}


function getPreviousPostContent($post_id) {
$current_post = get_post($post_id);
# Parse the URL and get the query param.
$query_param = parse_url($current_post->guid, PHP_URL_QUERY);

global $wpdb;

# By using the guid value from current_post, get the previous post_id.
$query = " SELECT * FROM " . $wpdb->prefix . "posts
WHERE ID != " . $post_id . " AND post_status NOT IN ('trash', 'inherit')
AND guid LIKE '%?" . $query_param . "' ORDER BY ID DESC LIMIT 1";
$previous_post = $wpdb->get_results($query);
if (empty($previous_post)) {
return False;
}
# Get the first record and convert to array.
$previous_post = (array) $previous_post[0];
# returns an empty string when the value of the page_template is either empty or 'default'.
$page_template = get_page_template_slug($previous_post['ID']);
if (empty($page_template)) {
$previous_post['page_template'] = 'default';
} else{
$previous_post['page_template'] = $page_template;
}

# Now delete the previous Post. True => Force delete
# wp_delete_post($previous_post['ID'], true);

# Return the content of the Previous post.
return $previous_post;
}

?>
40 changes: 40 additions & 0 deletions thanh/wp-sqli-tainted.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
rules:
- id: wp-sqli-tainted
mode: taint
options:
interfile: true
pattern-sources:
- pattern: $_POST
- pattern: $_GET
- pattern: $_COOKIE
- pattern: $_REQUEST
- pattern: $_SERVER
pattern-sanitizers:
- pattern: $wpdb->prepare(...)
pattern-sinks:
- pattern: $wpdb->query(...)
- pattern: $wpdb->get_var(...)
- pattern: $wpdb->get_row(...)
- pattern: $wpdb->get_col(...)
- pattern: $wpdb->get_results(...)
- pattern: $wpdb->replace(...)
message: Tainted SQL query worth investigating
languages:
- php
severity: WARNING
vulnerability_class:
- SQL Injection
metadata:
category: security
subcategory:
- audit
cwe:
- 'CWE 89: Improper Neutralization of Special Elements used in an SQL Command
(''SQL Injection'')'
confidence: LOW
likelihood: LOW
impact: LOW
technology:
- wordpress
references:
- https://example.com
Loading