Hiển thị các bài đăng có nhãn Resource. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Resource. Hiển thị tất cả bài đăng

Gởi email trong Laravel 8.x với Gmail SMTP Server

Phía dưới là ví dụ thật đơn giản làm thế nào để gởi email trong Laravel sử dụng Gmail SMTP server.

Giả lập là bạn đã có sẵn ứng dụng Laravel, các bạn theo dõi từng bước bên dưới nhé.

Bước 1: Cấu hình SMTP Server trong file .env

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=emailaddress@gmail.com
MAIL_PASSWORD=emailpassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=emailaddress@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

Gõ lệnh sau khi bạn điều chỉnh trong .env

#php artisan config:clear

Bạn cần bật tính năng "Less secure app access" của emailaddress@gmail.com sang chế độ ON nhé.


Bước 2: Tạo class Mail

Trong console, bạn gõ lệnh: 

#php artisan make:mail TestMail

Một file tạo ra trong app/Mail/TestMail.php, có nội dung

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class TestEmail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->subject('Email from Yours')
                    ->view('email.testemail'); //folder email và file testemail.blade.php
    }
}


Bước 3: Tạo Blade View

<body>
    <h1>{{ 'Hello! This is email from Yours' }}</h1>
    <p>{{ 'This is testing email is sent from Gmail smtp' }}</p>
   
    <p>Thank you</p>    
</body>


Bước 4: Thêm Route

Tạo route cho trình gởi email, thêm đoạn code sau vào file routes\web.php

Route::get('/sendemail', function () {
   
    $details = [
        'title',
        'body'
    ];
   
    \Mail::to('sento_email_address@dot.com')->send(new \App\Mail\TestEmail($details));
   
    echo "Email is Sent.";
});


Bước 5: Chạy ứng dụng và kiểm tra

Chạy lệnh khởi động ứng dụng:

#php artisan serve

và truy cập:  

http://localhost:8000/sendmail

Lần đầu tiên, có thể email sẽ bị vào thư mục spam của hộp thư bạn nhé.

Nạp chồng - ghi đè (Overload - override) trong Java

Nạp chồng - ghi đè (Overload - override) trong Java

- Thông thường 1 chương trình java đi qua 5 pha bao gồm edit, compile, load, verify, execute. 

+ Pha 1: Creating a Program
Tạo 1 file với 1 chương trình soạn thảo(editor) và lưu trong ổ đĩa cứng là tenfile.java
+ Pha 2: Compiling a Java Program into Bytecodes
Biên dịch (compiles) từ tenfile.java -> tenfile.class 
+ Pha 3: Loading a program into memory
Load tenfile.class(chứa bytecode) từ ổ đĩa cứng và đặt bytecodes vào trong bộ nhớ. Chú ý chương trình phải được đặt trong bộ nhớ trước khi nó được thực thi.
+ Pha 4: Bytecodes Verification
Sau khi bytecodes đã được nạp vào trong bộ nhớ thì tiến hành kiểm tra xác nhận rằng bytecode là hợp lệ và không vi phạm giới hạn bảo mật của java(như virus). Pha này thuộc vấn đề chuyên sâu liên quan đến lập trình mạng mình cũng chưa hiểu rõ lắm.
+ Pha 5: Execution(or Runtime)
JVM sẽ đọc bytecode sau đó được chuyển vào ngôn ngữ lập trình cái mà máy tính có thể hiểu để thực thi chương trình

Source: E-book Java How to program, seventh edition - Page 40
How to Setup a Linux Firewall with PPPoE/NAT/iptables

How to Setup a Linux Firewall with PPPoE/NAT/iptables


PPPoE for Linux

Many Internet service providers are using the Point-to-Point Protocol over Ethernet (PPPoE) to provide residential Digital Subscriber Link (DSL) broadband Internet access. Most ISP’s do not support Linux and supply PPPoE clients only for Windows and Mac OS.
The PPPoE Protocol
PPPoE is a protocol for encapsulating PPP frames in Ethernet frames. PPP is a data-link-level protocol typically used to encapsulate network-level packets over an asynchronous serial line. This mode of usage is called asynchronous.
While PPP is a peer-to-peer protocol, PPPoE is initially a client-server protocol. The client (usually a personal computer) searches for a PPPoE server (called an access concentrator) and obtains the access concentrator’s MAC address and a session number. The process of setting up a PPPoE session is called discovery.
The Pseudo-TTY
The pppd program and the Linux kernel expect to transmit PPP frames over a TTY device. Luckily, UNIX (and Linux) support the concept of a pseudo-tty. This is a device which “looks” like a TTY, but instead of being connected to a physical terminal, it is connected to a UNIX process. Whenever something writes to the pseudo-tty, the data appears on the standard input of the back-end process. Whenever the back-end process writes to its standard output, the data may be read from the pseudo-tty.
Even more luckily, recent versions of pppd (2.3.7 and newer) support a pty option. This option automatically starts the back-end process and performs all the mundane operations required to connect it to a pseudo-tty. So to start the PPPoE link, you start pppd with the appropriate
pty option, which runs the pppoe executable connected to the pseudo-tty.
The MTU Problem
PPPoE introduces a real and annoying problem. The maximum Ethernet frame is 1518 bytes long. 14 bytes are consumed by the header, and 4 by the frame-check sequence, leaving 1500 bytes for the payload. For this reason, the Maximum Transmission Unit (MTU) of an Ethernet interface is usually 1500 bytes.
This is the largest IP datagram which can be transmitted over the interface without fragmentation. PPPoE adds another six bytes of overhead, and the PPP protocol field consumes two bytes, leaving 1492 bytes for the IP datagram. The MTU of PPPoE interfaces is therefore 1492 bytes.
When a TCP connection is initiated, each side can optionally specify the Maximum Segment Size (MSS). TCP chops a stream of data into segments, and MSS specifies the largest segment each side will accept. By default, the MSS is chosen as the MTU of the outgoing interface minus the usual size of the TCP and IP headers (40 bytes), which results in an MSS of 1460 bytes for an Ethernet interface.
TCP stacks try to avoid fragmentation, so they use an MSS which will not cause fragmentation on their outgoing interface. Unfortunately, there may be intermediate links with lower MTU’s which will cause fragmentation. Good TCP stacks perform path MTU discovery. In path MTU discovery, a TCP stack sets a special Don’t Fragment (DF) bit in the IP datagrams. Routers which cannot forward the datagram without fragmenting it are supposed to drop it and send an ICMP “Fragmentation-Required” datagram to the originating host.
The originating host then tries a lower MTU value. Unfortunately, many routers are anti-social and do not generate the fragmentation-required datagrams. Many firewalls are equally anti-social and drop all ICMP datagrams.
Now consider a client workstation on an Ethernet LAN connected to a PPPoE gateway. It opens a TCP connection to a web server. Because the Ethernet MTU is 1500, it suggests an MSS of 1460. The web server is also on an Ethernet and also suggests an MSS of 1460. The client then requests a web page. This request is typically small and reaches the web server. The server responds with many TCP segments, most of which are 1460 bytes long.
The maximum-sized segments result in 1500-byte IP datagrams and make their way to the DSL provider. The DSL provider cannot transmit a 1500-byte IP datagram over a PPPoE link, so it drops it (assume for now that the DF bit is set.) Furthermore, being anti-social, the DSL provider does not send an ICMP message to the web server.
The net result is that packets are silently dropped. The web client hangs waiting for data, and the web server keeps retransmitting until it finally gives up, or the connection is closed by the user aborting the web client.
One way around this is to artificially set an MSS for the default route on all LAN hosts behind the PPPoE gateway. This is annoying, as it requires changes on each host. Instead, rp-pppoe “listens in” on the MSS negotiation and modifies the MSS if it is too big. Adjusting the MSS is a hack. It breaks the concept of the transport-layer being end-to-end. It will not work with IPSec, because IPSec will not let you damage IP packets (they will fail to authenticate.) Nevertheless, it is a fairly effective solution to an ugly real-world problem, and is used by default in rp-pppoe.
Installation and Configuration of PPP / PPPoE
We setup a GENTOO 2005.0 Linux machine with RP-PPPoE, PPP and the Firewall Software iptables. The internal network 192.168.138.0 is mapped to the dynamically asigned IP address using NAT / IP-Masquerading.
  1. Download PPP from Sambas Site, on GENTOO Linux use:

    emerge ppp
    This creates the directory/etc/ppp
     
  2. Download RP-PPPoE from RoaringPenguin

    tar xzvf rp-pppoe-xxx.tar.gz
    cd src
    ./configure
    make
    make install

    cd /etc/ppp
    ls -l
    -rw-------  1 root root   37 Jul 25 09:59 chap-secrets
    -rw-------  1 root root    0 Jul 25 09:59 chap-secrets-bak
    -rw-------  1 root root   78 Jul 25 09:42 chap-secrets.example
    -rw-r--r--  1 root root  353 Jul 25 09:42 chat-default
    -rw-r--r--  1 root root  938 Jul 25 09:53 firewall-masq
    -rw-r--r--  1 root root  836 Jul 25 09:53 firewall-standalone
    -rwxr-xr-x  1 root root  931 Jul 25 09:42 ip-down*
    -rwxr-xr-x  1 root root 1081 Jul 25 09:42 ip-up*
    -rw-r--r--  1 root root    5 Jul 25 09:42 options
    -rw-r--r--  1 root root   53 Jul 25 09:42 options-pppoe
    -rw-r--r--  1 root root  238 Jul 25 09:42 options-pptp
    -rw-------  1 root root   37 Jul 25 09:59 pap-secrets
    -rw-------  1 root root    0 Jul 25 09:59 pap-secrets-bak
    -rw-------  1 root root   77 Jul 25 09:42 pap-secrets.example
    drwxr-xr-x  2 root root 4096 Jul 25 09:42 peers/
    drwxr-xr-x  2 root root 4096 Jul 25 09:53 plugins/
    -rw-r--r--  1 root root 4592 Jul 25 09:59 pppoe.conf
    -rw-------  1 root root 4562 Jul 25 09:59 pppoe.conf-bak
    -rw-r--r--  1 root root  104 Jul 25 09:53 pppoe-server-options
How to Connect
  1. Set up your Ethernet hardware

    First, make sure the Ethernet card you intend to use with the modem is visible to the Linux kernel.

    ifconfig eth0

    should display something like this:

    eth0 Link encap:Ethernet HWaddr 00:60:67:62:31:D4

    plust some more lines. Your HWaddr will be different. DO NOT assign an IP address to the Ethernet card. DO NOT configure the card to come up at boot time.
     Note, that the PPP-Interface (ppp0) is automatically setup by PPPoE/PPP, it cannot be setup manually.
     
  2. Configure various files

    Several files need editing. The easiest way to do this is to run the following command as root:

    adsl-setup

    Answer the questions and you should be all set. If you want to know what goes on behind, continue reading.
     
  3. Edit pap-secrets

    "xx.xyz@domain.ch" * "xxxxxxx"

    Edit the "pap-secrets" file, inserting your proper user-ID and password. Install the file (or copy the relevant lines) to /etc/ppp/pap-secrets. Your ISP may use CHAP authentication. In this case, add the line to /etc/ppp/chap-secrets.
     
  4. Edit pppoe.conf
    The file /etc/ppp/pppoe.conf contains configuration information for the ADSL connection.

    #***********************************************************************
    #
    # pppoe.conf
    #
    # Configuration file for rp-pppoe.  Edit as appropriate and install in
    # /etc/ppp/pppoe.conf
    #
    # NOTE: This file is used by the adsl-start, adsl-stop, adsl-connect and
    #       adsl-status shell scripts.  It is *not* used in any way by the
    #       "pppoe" executable.
    #
    # Copyright (C) 2000 Roaring Penguin Software Inc.
    #
    # This file may be distributed under the terms of the GNU General
    # Public License.
    #
    # LIC: GPL
    # $Id: pppoe.conf,v 1.10 2002/04/09 17:28:38 dfs Exp $
    #***********************************************************************

    # When you configure a variable, DO NOT leave spaces around the "=" sign.
    # Ethernet card connected to ADSL modem
    ETH='eth0'

    # ADSL user name.  You may have to supply "@provider.com"  Sympatico
    # users in Canada do need to include "@sympatico.ca"
    # Sympatico uses PAP authentication.  Make sure /etc/ppp/pap-secrets
    # contains the right username/password combination.
    # For Magma, use xxyyzz@magma.ca

    USER='xx.xyz@domain.ch'

    # Bring link up on demand?  Default is to leave link up all the time.
    # If you want the link to come up on demand, set DEMAND to a number indicating
    # the idle time after which the link is brought down.

    DEMAND=no
    #DEMAND=300

    # DNS type: SERVER=obtain from server; SPECIFY=use DNS1 and DNS2;
    # NOCHANGE=do not adjust.
    DNSTYPE=SPECIFY

    # Obtain DNS server addresses from the peer (recent versions of pppd only)
    # In old config files, this used to be called USEPEERDNS.  Changed to
    # PEERDNS for better Red Hat compatibility
    PEERDNS=no

    DNS1=195.186.4.111
    DNS2=195.186.1.111

    # Make the PPPoE connection your default route.  Set to
    # DEFAULTROUTE=no if you don't want this.

    DEFAULTROUTE=yes

    ### ONLY TOUCH THE FOLLOWING SETTINGS IF YOU'RE AN EXPERT

    # How long adsl-start waits for a new PPP interface to appear before
    # concluding something went wrong.  If you use 0, then adsl-start
    # exits immediately with a successful status and does not wait for the
    # link to come up.  Time is in seconds.
    #
    # WARNING WARNING WARNING:
    #
    # If you are using rp-pppoe on a physically-inaccessible host, set
    # CONNECT_TIMEOUT to 0.  This makes SURE that the machine keeps trying
    # to connect forever after adsl-start is called.  Otherwise, it will
    # give out after CONNECT_TIMEOUT seconds and will not attempt to
    # connect again, making it impossible to reach.

    CONNECT_TIMEOUT=30

    # How often in seconds adsl-start polls to check if link is up
    CONNECT_POLL=2

    # Specific desired AC Name
    ACNAME=

    # Specific desired service name
    SERVICENAME=

    # Character to echo at each poll.  Use PING="" if you don't want
    # anything echoed

    PING="."

    # File where the adsl-connect script writes its process-ID.
    # Three files are actually used:
    #   $PIDFILE       contains PID of adsl-connect script
    #   $PIDFILE.pppoe contains PID of pppoe process
    #   $PIDFILE.pppd  contains PID of pppd process

    CF_BASE=`basename $CONFIG`
    PIDFILE="/var/run/$CF_BASE-adsl.pid"

    # Do you want to use synchronous PPP?  "yes" or "no".  "yes" is much
    # easier on CPU usage, but may not work for you.  It is safer to use
    # "no", but you may want to experiment with "yes".  "yes" is generally
    # safe on Linux machines with the n_hdlc line discipline; unsafe on others.

    SYNCHRONOUS=no

    # Do you want to clamp the MSS?  Here's how to decide:
    # - If you have only a SINGLE computer connected to the ADSL modem, choose
    #   "no".
    # - If you have a computer acting as a gateway for a LAN, choose "1412".
    #   The setting of 1412 is safe for either setup, but uses slightly more
    #   CPU power.
    CLAMPMSS=1412
    #CLAMPMSS=no

    # LCP echo interval and failure count.
    LCP_INTERVAL=20
    LCP_FAILURE=3

    # PPPOE_TIMEOUT should be about 4*LCP_INTERVAL
    PPPOE_TIMEOUT=80

    # Firewalling: One of NONE, STANDALONE or MASQUERADE
    FIREWALL=NONE

    # Linux kernel-mode plugin for pppd.  If you want to try the kernel-mode
    # plugin, use LINUX_PLUGIN=/etc/ppp/plugins/rp-pppoe.so

    LINUX_PLUGIN=

    # Any extra arguments to pass to pppoe.  Normally, use a blank string
    # like this:

    PPPOE_EXTRA=""

    # Rumour has it that "Citizen's Communications" with a 3Com
    # HomeConnect ADSL Modem DualLink requires these extra options:

    # PPPOE_EXTRA="-f 3c12:3c13 -S ISP"

    # Any extra arguments to pass to pppd.  Normally, use a blank string
    # like this:
    PPPD_EXTRA=""

    ########## DON'T CHANGE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
    # If you wish to COMPLETELY overrride the pppd invocation:
    # Example:
    # OVERRIDE_PPPD_COMMAND="pppd call dsl"

    # If you want adsl-connect to exit when connection drops:
    # RETRY_ON_FAILURE=no
     
  5.  Set up DNS

    If you are using DNS servers supplied by your ISP, edit the file /etc/resolv.conf
     
  6. Bring up the connection at boot time (For GENTOO)

    #!/sbin/runscript
    depend() {
    need net
    use logger dns
    }

    # Paths to programs
    START=/usr/sbin/adsl-start
    STOP=/usr/sbin/adsl-stop
    STATUS=/usr/sbin/adsl-status

    start() {
    ebegin "Bringing up ADSL link"
    $START &>/dev/null
    touch /var/lock/subsys/adsl
    eend $?
    }

    stop() {
    ebegin "Shutting down ADSL link"
    $STOP &>/dev/null
    rm -f /var/lock/subsys/adsl
    eend $?
    }
     
  7. Commands to control the ADSL link
    As root, bring up the link by typing: adsl-start
    As root, bring down the link by typing: adsl-stop
    ps -ef
    /usr/sbin/adsl-connect
    /usr/sbin/pppd pty /usr/sbin/pppoe -p /var/run/pppoe.conf-adsl.pid.pppoe \
       -I eth0 -T 80 -U -m 1412 noipdefa
    /usr/sbin/pppoe -p /var/run/pppoe.conf-adsl.pid.pppoe \
       -I eth0 -T 80 -U -m 1412
    ifconfig -a
    eth0      Link encap:Ethernet  HWaddr 00:30:48:28:AA:4A
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:23529 errors:0 dropped:0 overruns:0 frame:0
              TX packets:18759 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:22942360 (21.8 Mb)  TX bytes:1973186 (1.8 Mb)
              Base address:0x3000 Memory:fc200000-fc220000

    eth1      Link encap:Ethernet  HWaddr 00:30:48:28:AA:4B
              inet addr:192.168.138.1  Bcast:192.168.138.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:18130 errors:0 dropped:0 overruns:0 frame:0
              TX packets:25373 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:1819853 (1.7 Mb)  TX bytes:21836499 (20.8 Mb)
              Base address:0x3040 Memory:fc220000-fc240000

    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:16 errors:0 dropped:0 overruns:0 frame:0
              TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:1590 (1.5 Kb)  TX bytes:1590 (1.5 Kb)

    ppp0      Link encap:Point-to-Point Protocol
              inet addr:213.3.5.17  P-t-P:195.186.253.131  Mask:255.255.255.255
              UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1
              RX packets:21685 errors:0 dropped:0 overruns:0 frame:0
              TX packets:14272 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:3
              RX bytes:22260398 (21.2 Mb)  TX bytes:1314858 (1.2 Mb)
    netstat -nr
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    195.186.253.131 0.0.0.0         255.255.255.255 UH        0 0          0 ppp0
    192.168.138.0   0.0.0.0         255.255.255.0   U         0 0          0 eth1
    127.0.0.0       127.0.0.1       255.0.0.0       UG        0 0          0 lo
    0.0.0.0         195.186.253.131 0.0.0.0         UG        0 0          0 ppp0
    adsl-status
    adsl-status: Link is up and running on interface ppp0
    ppp0      Link encap:Point-to-Point Protocol
              inet addr:213.3.5.17  P-t-P:195.186.253.131  Mask:255.255.255.255
              UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1
              RX packets:2432 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2145 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:3
              RX bytes:628102 (613.3 Kb)  TX bytes:241917 (236.2 Kb)

Using A Zyxel Router as a Modem (Bridged Mode)

Connect to your Zyxel Router using TELNET. In Menu 1, change Route IP = No, Bridge = Yes.
In Menu 4, change Encapsulation to RFC 1483. Make sure VPI and VCI are setup correct for your Provider.
In Menu 11.2, change Route = None, Bridge = Yes.

Now, reboot the Modem ... it's now a Modem no more a Router. All settings are ignored, the Modem can no longer talk PPPoE!

Linux Routing

The first task to undertake when configuring the firewall ruleset is to turn on all the options you would like the kernel to use when processing IP packets. The very first thing is that you turn ip_forwarding off - it will be turned on after everything is done. We have set the following kernel options in the /etc/conf.d/local.start.
# /etc/conf.d/local.start:
# Setup Kernel Options for iptables/Firewall"

# If your firewall has a dynamic IP address, use this setting
echo 2 > /proc/sys/net/ipv4/ip_dynaddr

# Hardening settings:
if [ -e /proc/sys/net/ipv4/conf/all/accept_source_route ]; then
  for f in /proc/sys/net/ipv4/conf/*/accept_source_route
  do
   echo 0 > $f
  done
fi


# Do not respond to 'redirected' packets
if [ -e /proc/sys/net/ipv4/conf/all/send_redirects ]; then
  for f in /proc/sys/net/ipv4/conf/*/send_redirects
  do
   echo 0 > $f
  done
fi


# Do not reply to 'proxyarp' packets
if [ -e /proc/sys/net/ipv4/conf/all/proxy_arp ]; then
  for f in /proc/sys/net/ipv4/conf/*/proxy_arp
  do
   echo 0 > $f
  done
fi


# Detecting and stopping spoofed packets
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]; then
  for f in /proc/sys/net/ipv4/conf/*/rp_filter
  do
   echo 1 > $f
  done
fi


# Ignore source routing (dictating what route the traffic will take)
# from the origin of the packet as dictated by the client

echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
if [ -e /proc/sys/net/ipv4/conf/all/accept_source_route ]; then
  for f in /proc/sys/net/ipv4/conf/*/accept_source_route
  do
   echo 0 > $f
  done
fi


# Suppress ICMP redirects
if [ -e /proc/sys/net/ipv4/conf/all/accept_redirects ]; then
  for f in /proc/sys/net/ipv4/conf/*/accept_redirects
  do
   echo 0 > $f
  done
fi
if [ -e /proc/sys/net/ipv4/conf/all/send_redirects ]; then
  for f in /proc/sys/net/ipv4/conf/*/send_redirects
  do
   echo 0 > $f
  done
fi
if [ -e /proc/sys/net/ipv4/conf/all/secure_redirects ]; then
  for f in /proc/sys/net/ipv4/conf/*/secure_redirects
  do
   echo 0 > $f
  done
fi


echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 > /proc/sys/net/ipv4/ip_forward

NAT (Network Address Translation)

Normally, packets on a network travel from their source to their destination through many different links. None of these links really alter your packet: they just send it onward.
If one of these links were to do NAT, then they would alter the source or destinations of the packet as it passes through. As you can imagine, this is not how the system was designed to work, and hence NAT is always something of a crock. Usually the link doing NAT will remember how it mangled a packet, and when a reply packet passes through the other way, it will do the reverse mangling on that reply packet, so everything works.
Why Would I Want To Do NAT?
In a perfect world, you wouldn't. Meanwhile, the main reasons are:
  • Modem Connections To The Internet
Most ISPs give you a single IP address when you dial up to them. You can send out packets with any source address you want, but only replies to packets with this source IP address will return to you. If you want to use multiple different machines (such as a home network) to connect to the Internet through this one link, you'll need NAT.
This is by far the most common use of NAT today, commonly known as «masquerading» in the Linux world. I call this SNAT, because you change the source address of the first packet.
  • Multiple Servers
Sometimes you want to change where packets heading into your network will go. Frequently this is because (as above), you have only one IP address, but you want people to be able to get into the boxes behind the one with the real IP address. If you rewrite the destination of incoming packets, you can manage this. This type of NAT was called port-forwarding under previous versions of Linux.
  • Transparent Proxying
Sometimes you want to pretend that each packet which passes through your Linux box is destined for a program on the Linux box itself. This is used to make transparent proxies: a proxy is a program which stands between your network and the outside world, shuffling communication between the two. The transparent part is because your network won't even know it's talking to a proxy, unless of course, the proxy doesn't work. Squid can be configured to work this way, and it is called redirection or transparent proxying under previous Linux versions.
The Two Types of NAT
NAT is divided into two different types: Source NAT (SNAT) and Destination NAT (DNAT).
  • SNAT
Source NAT is when you alter the source address of the first packet: i.e. you are changing where the connection is coming from. Source NAT is always done post-routing, just before the packet goes out onto the wire. Masquerading is a specialized form of SNAT.
  • DNAT
Destination NAT is when you alter the destination address of the first packet: i.e. you are changing where the connection is going to. Destination NAT is always done before routing, when the packet first comes off the wire. Port forwarding, load sharing, and transparent proxying are all forms of DNAT.
Examples
Here are our NAT rules as examples.
# echo "Static NAT: Masquerade our Traffic"
# $IPTABLES -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

echo "Static NAT to IP: 213.3.5.17"
$IPTABLES -t nat -A POSTROUTING -o ppp0 -j SNAT --to 213.3.5.17


echo "DNAT Portforwarding: 25 --> 192.168.138.28:25"
$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 25 -j DNAT --to 192.168.138.28:25

echo "DNAT Portforwarding: 53 --> 192.168.138.20:25"
$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 53 -j DNAT --to 192.168.138.20:53
$IPTABLES -t nat -A PREROUTING -p udp -i ppp0 --dport 53 -j DNAT --to 192.168.138.20:53

echo "DNAT Portforwarding: 80 --> 192.168.138.21:80"
$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 80 -j DNAT --to 192.168.138.21:80

Firewall with netfilter/iptables

netfilter and iptables are building blocks of a framework inside the Linux 2.4.x and 2.6.x kernel. This framework enables packet filtering, network address translation and other packet mangling. It is the re-designed and heavily improved successor of the previous Linux 2.2.x ipchains and Linux 2.0.x ipfwadm systems.
netfilter is a set of hooks inside the Linux kernel that allows kernel modules to register callback functions with the network stack. A registered callback function is then called back for every packet that traverses the respective hook within the network stack.
iptables is a generic table structure for the definition of rulesets. Each rule within an IP table consists of a number of classifiers (iptables matches) and one connected action (iptables target).
Main Features
  • stateless packet filtering (IPv4 and IPv6)
  • stateful packet filtering (IPv4)
  • all kinds of network address and port translation (NAT/NAPT)
  • flexible and extensible infrastructure
  • multiple layers of API's for 3rd party extensions
  • large number of plugins/modules kept in 'patch-o-matic' repository
What can I do with netfilter/iptables?
  • build internet firewalls based on stateless and stateful packet filtering
  • use NAT and masquerading for sharing internet access if you don't have enough public IP addresses
  • use NAT to implement transparent proxies
  • aid the tc and iproute2 systems used to build sophisticated QoS and policy routers
  • do further packet manipulation (mangling) like altering the TOS/DSCP/ECN bits of the IP header
An iptable tutortial can be found here.
Stateful Inspection and Connection Tracking
Stateful packet inspection uses the same fundamental packet screening technique that packet filtering does. In addition, it examines the packet header information from the network layer of the OSI model to the application layer to verify that the packet is part of a legitimate connection and the protocols are behaving as expected.
The stateful packet inspection process is accomplished in the following manner. As packets pass through the firewall, packet header information is examined and fed into a dynamic state table where it is stored. The packets are compared to pre-configured rules or filters and allow or deny decisions are made based on the results of the comparison. The data in the state table is then used to evaluate subsequent packets to verify that they are part of the same connection. In short, stateful packet inspection uses a two step process to determine whether or not packets will be allowed or denied. This method can make decisions based on one or more of the following:
  • Source IP address
  • Destination IP address
  • Protocol type (TCP/UDP)
  • Source port
  • Destination port
  • Connection state
The connection state is derived from information gathered in previous packets. It is an essential factor in making the decision for new communication attempts. Stateful packet inspection compares the packets against the rules or filters and then checks the dynamic state table to verify that the packets are part of a valid, established connection. By having the ability to "remember" the status of a connection, this method of packet screening is better equipped to guard against attacks than standard packet filtering.
Stateful packet inspection solutions offer sophisticated decision-making capabilities, yet they operate faster than other packet screening methods because they require little processing overhead. Allow and deny decisions are made at the lower levels of the OSI model.
Some newer stateful packet inspection firewalls maintain more advanced connection state information. Some are able to reassemble the packets as they pass through the firewall and perform additional processing such as content filtering.
Connection States
  • NEW

    This packet is trying to create a new connection. Unless you're running a server you shouldn't allow these on the input side.
     
  • RELATED

    This packet is related to the existing connection, and is passing in the original direction
    .
     
  • INVALID

    his packet doesn't match any connection
     
  • ESTABLISHED

    This packet is part of an existing connection
As a simple example, to forward across the firewall interfaces packets that are part of a pre-existing connection might look like this:
iptables -A FORWARD -m state -state ESTABLISHED,RELATED -j ACCEPT
Installation and Configuration
  1. Download iptables from netfilter.org, on GENTOO use

    emerge iptables
     
  2. Prepare the Kernel

    cd /usr/src/linux
    make menuconfig
    (Enable Network packet filtering in Networking options)
     
  3. Download Firewall Builder from fwbuilder.org

    With this tool, you can build the basic iptables rules. Here are our basic rules.
    #!/bin/sh

    # Akadia AG, Fichtenweg 10, 3672 Oberdiessbach
    # --------------------------------------------------------------------------
    # File:        firewall.fw
    #
    # Autor:       Martin Zahn, 28.07.2005
    #
    # Purpose:     Configuration file IPTABLES Firewall
    #
    # Location:    /home/zahn/iptables
    #
    # Load Rules:  ./firewall.fw
    # Save Rules:  /etc/init.d/iptables save
    #
    # --------------------------------------------------------------------------
    #

    PATH="/sbin:/usr/sbin:/bin:/usr/bin:${PATH}"
    export PATH

    log() {
      echo "$1"
      test -x "$LOGGER" && $LOGGER -p info "$1"
    }

    va_num=1
    add_addr() {
      addr=$1
      nm=$2
      dev=$3

      type=""
      aadd=""

      L=`$IP -4 link ls $dev | head -n1`
      if test -n "$L"; then
        OIFS=$IFS
        IFS=" /:,<"
        set $L
        type=$4
        IFS=$OIFS

        L=`$IP -4 addr ls $dev to $addr | grep inet | grep -v :`
        if test -n "$L"; then
          OIFS=$IFS
          IFS=" /"
          set $L
          aadd=$2
          IFS=$OIFS
        fi
      fi
      if test -z "$aadd"; then
        if test "$type" = "POINTOPOINT"; then
          $IP -4 addr add $addr dev $dev scope global label $dev:FWB${va_num}
          va_num=`expr $va_num + 1`
        fi
        if test "$type" = "BROADCAST"; then
          $IP -4 addr add $addr/$nm dev $dev brd + scope global label $dev:FWB${va_num}
          va_num=`expr $va_num + 1`
        fi
      fi
    }

    getInterfaceVarName() {
      echo $1 | sed 's/\./_/'
    }

    getaddr() {
      dev=$1
      name=$2
      L=`$IP -4 addr show dev $dev | grep inet | grep -v :`
      test -z "$L" && {
        eval "$name=''"
        return
      }
      OIFS=$IFS
      IFS=" /"
      set $L
      eval "$name=$2"
      IFS=$OIFS
    }

    getinterfaces() {
      NAME=$1
      $IP link show | grep ": $NAME" | while read L; do
        OIFS=$IFS
        IFS=" :"
        set $L
        IFS=$OIFS
        echo $2
      done
    }

    LSMOD="lsmod"
    MODPROBE="modprobe"
    IPTABLES="iptables"
    IPTABLES_RESTORE="iptables-restore"
    IP="ip"
    LOGGER="logger"

    getaddr ppp0  i_ppp0

    log 'Activating firewall script'

    echo "Cleanup iptables Rules"
    $IPTABLES -P OUTPUT  DROP
    $IPTABLES -P INPUT   DROP
    $IPTABLES -P FORWARD DROP
    # $IPTABLES -F
    # $IPTABLES -X

    cat /proc/net/ip_tables_names | while read table; do
      test "X$table" = "Xmangle" && continue
      $IPTABLES -t $table -L -n | while read c chain rest; do
          if test "X$c" = "XChain" ; then
            $IPTABLES -t $table -F $chain
          fi
      done
      $IPTABLES -t $table -X
    done

    # echo "Mainly for PPPoE, VPN and DSL (MTU Fix, activate it if you have)"
    # echo "Problems with large Downloads over PPPoE"
    # $IPTABLES -A OUTPUT -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
    # $IPTABLES -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
    #
    echo "Connection Tracking Rules"
    $IPTABLES -A INPUT   -m state --state ESTABLISHED,RELATED -j ACCEPT
    $IPTABLES -A OUTPUT  -m state --state ESTABLISHED,RELATED -j ACCEPT
    $IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
    #
    # echo "NAT: Masquerade our Traffic"
    # $IPTABLES -t nat -A POSTROUTING -o ppp0  -j MASQUERADE

    echo "Static NAT to IP: 213.3.5.17"
    $IPTABLES -t nat -A POSTROUTING -o ppp0 -j SNAT --to 213.3.5.17


    # echo "Portforwarding: 25 --> 192.168.138.28:25"$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 25 -j DNAT --to 192.168.138.28:25
    # echo "Portforwarding: 53 --> 192.168.138.28:25"$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 53 -j DNAT --to 192.168.138.28:53
    $IPTABLES -t nat -A PREROUTING -p udp -i ppp0 --dport 53 -j DNAT --to 192.168.138.28:53


    # echo "Portforwarding: 80,8080,8081 --> 192.168.138.28:80,8080,8081"
    $IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 80 -j DNAT --to 192.168.138.28:80
    $IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 8080 -j DNAT --to 192.168.138.28:8080
    $IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 8081 -j DNAT --to 192.168.138.28:8081


    # echo "Portforwarding: 143 --> 192.168.138.28:143"$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 143 -j DNAT --to 192.168.138.28:143#echo "Anti Spoofing Rule"
    $IPTABLES -N ppp0_In_RULE_0
    test -n "$i_ppp0" && $IPTABLES -A INPUT  -i ppp0  -s $i_ppp0  -j ppp0_In_RULE_0
    $IPTABLES -A INPUT  -i ppp0  -s 192.168.138.1  -j ppp0_In_RULE_0
    $IPTABLES -A INPUT  -i ppp0  -s 192.168.138.0/24  -j ppp0_In_RULE_0
    test -n "$i_ppp0" && $IPTABLES -A FORWARD  -i ppp0  -s $i_ppp0  -j ppp0_In_RULE_0
    $IPTABLES -A FORWARD  -i ppp0  -s 192.168.138.1  -j ppp0_In_RULE_0
    $IPTABLES -A FORWARD  -i ppp0  -s 192.168.138.0/24  -j ppp0_In_RULE_0
    $IPTABLES -A ppp0_In_RULE_0   -j LOG  --log-level info --log-prefix "RULE 0 -- DENY "
    $IPTABLES -A ppp0_In_RULE_0   -j DROP

    #echo "Loopback (lo) Rules"
    $IPTABLES -A INPUT  -i lo  -m state --state NEW  -j ACCEPT
    $IPTABLES -A OUTPUT  -o lo  -m state --state NEW  -j ACCEPT

    #
    echo "Allow the following TCP Ports from Aynwhere"

    $IPTABLES -A OUTPUT  -p tcp -m tcp -m multiport --dports 22,80,443,25,143,8080,8081 \
      -m state --state NEW -j ACCEPT
    $IPTABLES -A INPUT   -p tcp -m tcp -m multiport --dports 22,80,443,25,143,8080,8081 \
      -m state --state NEW -j ACCEPT
    $IPTABLES -A FORWARD -p tcp -m tcp -m multiport --dports 22,80,443,25,143,8080,8081 \
      -m state --state NEW -j ACCEPT

    #
    echo "Allow DNS Zone Transfer only from 62.2.210.211"
    $IPTABLES -A OUTPUT  -p tcp -m tcp -d 62.2.210.211 --dport 53 -m state --state NEW -j ACCEPT
    $IPTABLES -A INPUT   -p tcp -m tcp -d 62.2.210.211 --dport 53 -m state --state NEW -j ACCEPT
    $IPTABLES -A FORWARD -p tcp -m tcp -d 62.2.210.211 --dport 53 -m state --state NEW -j ACCEPT
    #
    echo "Allow DNS Queries"
    $IPTABLES -A OUTPUT  -p udp -m udp  --dport 53 -m state --state NEW -j ACCEPT
    $IPTABLES -A INPUT   -p udp -m udp  --dport 53 -m state --state NEW -j ACCEPT
    $IPTABLES -A FORWARD -p udp -m udp  --dport 53 -m state --state NEW -j ACCEPT

    #
    echo "Allow NTP Time to setup the Date/Time from NTP Server"
    $IPTABLES -A OUTPUT  -p udp -m udp --dport 123 -m state --state NEW -j ACCEPT
    $IPTABLES -A INPUT   -p udp -m udp --dport 123 -m state --state NEW -j ACCEPT
    $IPTABLES -A FORWARD -p udp -m udp --dport 123 -m state --state NEW -j ACCEPT

    #
    echo "HSZ Rules"

    $IPTABLES -A INPUT  -s 192.168.138.0/24  -m state --state NEW  -j ACCEPT
    $IPTABLES -A OUTPUT  -s 192.168.138.0/24  -m state --state NEW  -j ACCEPT
    $IPTABLES -A FORWARD  -s 192.168.138.0/24  -m state --state NEW  -j ACCEPT

    #
    echo "Logging Rules"$IPTABLES -N RULE_2
    $IPTABLES -A OUTPUT  -j RULE_2
    $IPTABLES -A INPUT  -j RULE_2
    $IPTABLES -A FORWARD  -j RULE_2
    $IPTABLES -A RULE_2  -j LOG  --log-level info --log-prefix "RULE 2 -- DENY "
    $IPTABLES -A RULE_2  -j DROP
    #
    echo "Activate Routing"
    echo 1 > /proc/sys/net/ipv4/ip_forward
     
  4. Load and Save the Rules

    ./firewall.fw
    /etc/init.d/iptables save
    The iptables rules are saved and automatically loaded when the machine is booting the next time. The location of the saved rules are defined in/etc/conf.d/iptables (/var/lib/iptables/rules-save) for GENTOO linux.
Useful iptables Commands
iptables -L          (List Rules)
iptables -t nat -L   (List NAT Rules)

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  anywhere             anywhere            tcp dpt:smtp to:192.168.138.28:25
DNAT       tcp  --  anywhere             anywhere            tcp dpt:domain to:192.168.138.20:53
DNAT       udp  --  anywhere             anywhere            udp dpt:domain to:192.168.138.20:53
DNAT       tcp  --  anywhere             anywhere            tcp dpt:www to:192.168.138.21:80

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
SNAT       all  --  anywhere             anywhere            to:213.3.5.17

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
iptables -F    (Delete all rules)
iptables -X    (Delete all userdefined chains)

Source: www.akadia.com.
Tìm hiểu về các giao thức SMTP, POP, IMAP

Tìm hiểu về các giao thức SMTP, POP, IMAP

Chuẩn Internet cho e-mail là Simple Mail Transport Protocol (SMTP). SMTP là nghi thức cấp ứng dụng (application-level) dùng để điều khiển các dịch vụ thông điệp thông qua các mạng TCP/IP. SMTP được nói rõ trong RFC 321 và 822. SMTP sử dụng cổng TCP 25.

Bên cạnh SMTP, hai nghi thức khác dùng để phân phát mail đến client là POP3 và IMAP4.

MIME và SMTP
MIME (Multipurpose Internet Mail Extensions) bổ sung thêm cho SMTP để cho phép gắn kèm các thông điệp đa phương tiện (không phải là văn bản) bên trong thông điệp SMTP chuẩn. MIME sử dụng mã hóa Base64 để chuyển các file phức tạp sang ASCII. MIME được mô tả trong các RFC 2045-2049.

Các lệnh SMTP thường sử dụng:

HELO - Sử dụng để định danh máy gửi với máy nhận. Lệnh này phải kèm với tên máy tính của máy gửi. Trong nghi thức mở rộng (ESMTP), lệnh EHLO thay cho lệnh này.
MAIL - Khởi tạo một phiên gửi mail. Đối số bao gồm trường “FROM” và địa chỉ email của người gửi.
RCPT - Định danh người nhận thông điệp. Đi kèm với “TO” và địa chỉ email người nhận.
DATA - Thông báo bắt đầu gửi dữ liệu thực sự của mail (phần thân của message). Dữ liệu kết thúc bằng một dòng trống và một dấu chấm (.).
RSET - Hủy (reset) phiên gửi mail hiện hành.
VRFY - Sử dụng để xác nhận một người nhận mail.
NOOP - Viết tắt của “no operation”, lệnh này không làm gì cả.
QUIT - Đóng kết nối
SEND - Báo cho host nhận biết là message phải được gửi đến một terminal khác.
HELP - Yêu cầu thông tin trợ giúp từ host nhận.

Ví dụ một phiên giao dịch SMTP:

220 ntbooks-pro Microsoft ESMTP MAIL Service, Version: 6.0.2505.1 ready at Mon, 8 Jul 2002 17:44:12 -0700
HELO
250 ntbooks-pro Hello [192.168.0.1]
MAIL FROM : user1@mydomain.com
250 2.1.0 user1@mydomain.com....Sender OK
RCPT TO : user2@mydomain.com
250 2.1.5 user2@mydomain.com
DATA
354 Start mail input; end with .
mail test
ha ha ha

.
250 2.6.0 Queued mail for delivery
QUIT
221 2.0.0 ntbooks-pro Service closing transmission channel

Nội dung mail nhận được có dạng như sau:

Received: from ([192.168.0.1]) by ntbooks-pro with Microsoft SMTPSVC(6.0.2505.1); Mon, 8 Jul 2002 17:46:21 -0700
From: user1@mydomain.com
Bcc:
Return-Path: user1@mydomain.com
Message-ID:
X-OriginalArrivalTime: 09 Jul 2002 00:46:50.0836 (UTC) FILETIME=[1CDAC940:01C226E2]
Date: 8 Jul 2002 17:46:50 -0700

mail test

ha ha ha


Các mã trạng thái SMTP
Khi một sending host gửi một lệnh SMTP đến receiving host, host nhận trả về một mã trạng thái cho máy gửi biết là điều gì đã xảy ra. Danh sách bên dưới là code được nhóm theo số đầu tiên (5xx là lỗi, 4xx lỗi tạm thời, 1xx-3xx thành công):

211 Trả lời trợ giúp, trạng thái hệ thống
214 Help message
220 Dịch vụ sẳn sàng (Service ready)
221 Đóng kết nối
250 Hành động yêu cầu được chấp nhận
251 Người sử dụng không ở mạng cục bộ, chuyển đến
354 Bắt đầu nhập mail
421 Dịch vụ không sẳn sàng
450 Hành động không chấp nhận, mailbox bận
451 Hành động bị hũy, lỗi cục bộ
452 Hành động không chấp nhận, thiếu không gian lưu trữ
500 Không hiểu lệnh hoặc lỗi cú pháp
501 Lỗi cú pháp ở tham số
502 Lệnh không được hổ trợ
503 Sai thứ tự các lệnh
504 Tham số của lệnh không được hổ trợ
550 Hành động không chấp nhận, mailbox không có.
551 Không phải là người sử dụng cục bộ
552 Hũy lệnh do vượt quá không gian lưu trữ
553 Hành động không chấp nhận, tên mailbox không cho phép
554 Phiên dao dịch bị lỗi

Post Office Protocol (POP)

POP cho phép các mail client (UA – User Agent) ở máy cục bộ kết nối vào pop server (MTA – Message Transfer Agent) và lấy mail về máy tính cục bộ nơi mà người sử dụng có thể đọc và trả lời các message. POP được định nghĩa đầu tiên vào năm 1984, được nâng cấp trong POP2 vào năm 1988. Chuẩn hiện hành là POP3.
POP3 UA kết nối với TCP/IP đến server (cổng chuẩn 110). UA nhập vào một tên đăng nhập (username) và mật mã (password). Sau khi đăng nhập, UA sử dụng các lệnh POP3 để lấy và xóa mail.
POP3 là nghi thức chỉ để nhận mail. POP3 UA sử dụng SMTP để gửi mail đến server.
POP3 được mô tả trong RFC 1939.

Các lệnh của POP3

USER Chỉ rõ username
PASS Chỉ rõ password
STAT Yêu cầu trạn thái của mailbox (số lượng message, kích thước của các message)
LIST Liệt kê các message
RETR Lấy một message cụ thể
DELE Xóa một message cụ thể
NOOP Không làm gì cả
RSET Hủy hành động của các lệnh DELE (rollback)
QUIT Chấp nhận các thay đổi và cắt kết nối.

Internet Mail Access Protocol (IMAP)

POP3 là một nghi thức đơn giản. IMAP4 là một chuẩn mail khác có hổ trợ nhiều tính năng hơn.
IMAP4 được mô tả trong RFC 2060. IMAP4 sử dụng cổng TCP 143.

Các lệnh IMAP4

CAPABILITY Yêu cầu một danh sách các chức năng có hỗ trợ.
AUTHENTICATE Chỉ rõ cơ chế đăng nhập
LOGIN Cung cấp username và password
SELECT Chỉ rõ mailbox
EXAMINE Chỉ định mailbox ở chế độ chỉ đọc.
CREATE Tạo một mailbox
DELETE Xóa một mailbox
RENAME Đổi tên một mailbox
SUBSCRIBE Thêm một mailbox vào danh sách cho phép.
UNSUBSCRIBE Loại mailbox ra khỏi danh sách cho phép.
LIST Liệt kê các mailbox
LSUB Liệt kê các mailbox cho phép.
STATUS Yêu cầu trạng thái của mailbox
APPEND Thêm một message vào mailbox
CHECK Yêu cầu một mailbox checkpoint
CLOSE Chấp nhận các thao tác xóa và đóng mailbox
EXPUNGE Chấp nhận các thao tác xóa
SEARCH Tìm trong mailbox các message thỏa điều kiện cụ thể
FETCH Lấy một phần của một message cụ thể
STORE Thay đổi dữ liệu của message cụ thể
COPY Chép message sang một mailbox khác
NOOP Không làm gì cả
LOGOUT Đóng kết nối

Các lệnh RFC thực sự không phải là các lệnh ngôn ngữ lập trình, nó là các chuỗi dùng để gửi đến Server qua Socket được tạo với cổng tương ứng.Ví dụ, nếu muốn gửi mail, tạo một socket TCP cổng 25 với Server (ví dụ, Post Office) sau đó lần lượt gửi các lệnh RFC (kết thúc lệnh là ký tự ENTER) và nhận các trả lời từ server để gửi mail.
Cách nhanh nhất để thử các lệnh RFC là dùng chương trình Telnet. Ví dụ để gửi một mail, làm như sau:

Windows 2000: ở Command Prompt gõ lệnh:
Telnet mail.myserver.com 25
Sau đó gõ các lệnh như trong ví dụ đã nêu phần trước.
Nếu viết một Windows Application thì có thể dùng MAPI control của Windows, nếu viết (asp) Webmail có thể dùng CDO, các control này giúp cho người lập trình không cần biết RFC nhưng vẫn có thể viết được các ứng dụng mail bằng cách sử dụng các phương thức và các thuộc tính của chúng. Nhưng các control trên đều dùng các lệnh RFC để làm việc gửi và nhận mail thực sự.
Việc viết một ứng dụng bằng cách sử dụng trực tiếp RFC đòi hỏi người lập trình phải code nhiều (hầu như là mọi thứ), phải tìm hiểu nhiều chuẩn khác (MIME), các kiểu mã hóa (Base64, uuencode ,...), nếu viết Webmail phải tìm hiểu thêm upload file (để attach), cách tổ chức trên Webserver để quản lý mail đọc rồi và chưa đọc, hoặc tạo thêm các thư mục...

Từ Internet
Windows Hacking Rundll32 Shortcuts

Windows Hacking Rundll32 Shortcuts

Windows Hacking Rundll32 Shortcuts

"rundll32 shell32,Control_RunDLL" - Run Control Panel

"rundll32 shell32,OpenAs_RunDLL" - Mở cửa sổ 'Open With...'

"rundll32 shell32,ShellAboutA Info-Box" - Mở 'About Window Window'

"rundll32 shell32,Control_RunDLL desk.cpl" - Open Display Properties

"rundll32 user,cascadechildwindows" - Xếp tầng tất cả cửa sổ

"rundll32 user,tilechildwindows" - Minimize All Child-Windows

"rundll32 user,repaintscreen" - Refresh Desktop

"rundll32 shell,shellexecute Explorer" - Re-Start Windows Explorer

"rundll32 keyboard,disable" - Lock The Keyboard

"rundll32 mouse,disable" - Disable Mouse

"rundll32 user,swapmousebutton" - Swap Mouse Buttons

"rundll32 user,setcursorpos" - Set vị trí con trỏ sang (0,0)

"rundll32 user,wnetconnectdialog" - Hiển thị cửa sổ 'Map Network Drive'

"rundll32 user,wnetdisconnectdialog" - Hiển thị cửa sổ 'Disconnect Network Disk'

"rundll32 user,disableoemlayer" - Hiển thị cửa sổ BSOD
chú ý '''(BSOD) = Blue Screen Of Death '''

"rundll32 diskcopy,DiskCopyRunDll" - Hiển thị cửa sổ Copy Disk

"rundll32 rnaui.dll,RnaWizard" - Run 'Internet Connection Wizard', Nếu run với "/1" - silent mode

"rundll32 shell32,SHFormatDrive" - Run cửa sổ 'Format Disk (A)'

"rundll32 shell32,SHExitWindowsEx -1" - Restart Windows Explorer

"rundll32 shell32,SHExitWindowsEx 1" - Shut Down Computer

"rundll32 shell32,SHExitWindowsEx 0" - Logoff Current User

"rundll32 shell32,SHExitWindowsEx 2" Reboot nhanh Windows9x

"rundll32 krnl386.exe,exitkernel" - Bắt Windows 9x Exit

"rundll rnaui.dll,RnaDial "MyConnect" - Run 'Net Connection' Dialog

"rundll32 msprint2.dll,RUNDLL_PrintTestPage" - Choose & Print Test Page của Printer hiện thời

"rundll32 user,setcaretblinktime" - Set tốc độ của con trỏ

"rundll32 user, setdoubleclicktime" - Set tốc độ DblClick

"rundll32 sysdm.cpl,InstallDevice_Rundll" - Search For non PnP Devices

Source: HVAonline

Các loại Proxy Server và chức năng – Socks

Các loại Proxy Server và chức năng – Socks

1. Giới thiệu Proxy
Phân biệt Proxy theo chức năng, thì có rất nhiều kiểu chức năng (caching proxy server, web proxy, Content Filtering Web Proxy, Anonymizing proxy server, Intercepting proxy server..) . Ở ví dụ trong phần đầu, sau khi tìm kiếm được danh sách một loạt các Proxy server, tại mục Proxy type, có những loại sau: Anonymous, Transparent, High Anonymity, phân biệt các kiểu Proxy này nhự thế nào

Anonymous:
Đôi khi còn được gọi là web proxy, giúp người dùng ẩn danh (giấu IP), khi lướt Web. HTTP Proxy server không gửi thông số cụ thể của biến HTTP_X_FORWARDED_FOR tới Host đang truy cập, do vậy có thể che dấu IP của bạn. tuy nhiên, điều đó không có nghĩa giúp bạn ẩn dấu hoàn toàn, vì các website có thể sử dụng các site script để thu thập thông tin về việc bạn đang truy cập Host của họ thông qua một Proxy nào đó đang..phục vụ cho bạn

High Anonymity:
Mức độ che dấu tung tích cao hơn anonymous. Http Proxy hoàn toàn không gửi đi bất kì thông số nào của các biến HTTP_X_FORWARDED_FOR, HTTP_VIA và HTTP_PROXY_CONNECTION. Do vậy Internet Host không thể biết bạn đang dùng Proxy server, cũng như không detect được real IP của bạn

Transparent:
Proxy xuyên suốt, Đôi khi còn được gọi là Intercepting proxy, khác với 2 loại trên, transparent là sự kết hợp 1 proxy server và 1 gateway.

Đây là phương thức thường được các Network Admin “ép” User trong mạng Lan, User không nhận thức được mình đang truy cập internet qua một “cổng giám sát”.

Admin Mạng có đang theo dõi bạn khi bạn "đi qua" Proxy ?

Yêu cầu truy cập của Client đước chuyển đến gateway sau đó gateway chuyển sang Proxy server xử lý. Khi user dùng loại proxy này, thì họ không biết được rằng họ đang dùng 1 proxy và bị..kiểm soát. User chỉ cần thiết lập địa chỉ IP của gateway do Admin cung cấp, mà không phải xác lập các thông số Proxy trong trình duyệt cũng như Internet applications khác..

Thường được các Admin trong công ty triển khai, họ muốn các chính sách của Policy được áp đặt lên user, nhưng user hầu như không biết mình đang qua 1..proxy

2. HTTP proxy và Socks proxy là gì, khác nhau như thế nào ?

HTTP/HTTPS Proxy(proxy thông thường):
Các proxy servers sẵn sàng cho các dịch vụ thông thường trên internet, ví dụ như: một HTTP proxy được dùng cho truy cập Web, một FTP proxy được dùng cho truyền File.
Những Proxies trên, được gọi là application-level proxies hay “application-level gateways”, bởi vì chúng được chỉ định để làm việc với những application và protocol và nhận ra được nội dung các Packet được gửi đến nó.
Một hệ thống proxy khác được gọi là circuit-level proxy, hỗ trợ nhiều applications cùng lúc. ví dụ, SOCKS là một IP-based proxy server (circuit-level proxy), hổ trợ hầu hết các applications trên nền TCP và UDP

SOCKS hay Sockets:
Chính là một circuit-level proxy server cho các IP networks theo định nghĩa từ (IETF (Internet Engineering Task Force)- một cộng đồng các chuyên gia về network designers, operators, vendors, and researchers tham gia vào cuộc xây dựng kiến trúc Internet và ngày càng hoàn thiện Internet hơn.) SOCKS được viết bởi David và Michelle Koblas vào những năm đầu của thập niên 90.
SOCKS đã nhanh chóng trở thành một de facto standard (hardware hay software được dùng rộng rãi nhưng không được chứng nhận từ những tổ chức chuyên cung cấp các định chuẩn), ngược lại là de jure standard. Mặc dù SOCKS ra đời sớm và được dùng phổ biến, nhưng SOCKS được IETF thông qua lần đầu tiên là SOCKS5. SOCKS ban đầu là hệ thống Proxy được sủ dụng cho các traffic như FTP, Telnet, v.vv, nhưng không dành cho HTTP. SOCKS4 kiểm soát các TCP connections (là phần lớn các Application trên Internet), SOCKS5 còn hỗ trợ thêm UDP, ICMP, xác thực User (user authentication) và giải quyết hostname (DNS service).

SOCKS bắt buộc Client phải được cấu hình để chuyển trực tiếp các yêu cầu đến SOCKS server, hoặc ngược lại SOCKS driver sẽ ngăn chặn các Clients chuyển các yêu cầu non-SOCKS application. Nhiều Web browsers và các Internet applications khác hiện nay hỗ trợ SOCKS, cho nên khá dễ dàng khi làm việc với các SOCKS server. tìm hiểu chi tiết về SOCKS và các Applications tuân theo SOCKS Cũng cần xem thêm mô hình giao tiếp TCP/IP

Nguồn: vietmatrix.wordpress.com
Hiren's Boot 10 (Giới thiệu)

Hiren's Boot 10 (Giới thiệu)

Hiren's Boot 10 (Giới thiệu)

Hiren's Boot CD là một CD khởi động bao gồm các chương trình chẩn đoán khác nhau như theo dõi phân vùng, đo hiệu năng hệ thống, sao chép đĩa và công cụ hình ảnh, công cụ phục hồi dữ liệu, công cụ MBR , công cụ BIOS, và nhiều công cụ khác giúp sửa các lỗi khác nhau của máy tính. Nó là CD có khả năng Boot, do đó, nó có thể rất hữu dụng ngay cả khi hệ điều hành chính không thể khởi động. Hiren's Boot CD có danh sách phần mềm rất lớn. Các tiện ích có cùng tính năng trên CD được nhóm lại với nhau và có vẻ hơi thừa; thế nhưng, chúng thể hiện sự lựa chọn giữa các mặt khác nhau

Các công cụ phân vùng:
* Partition Magic Pro 8.05 - Phần mềm định dạng ổ cứng tốt nhất
* Acronis Disk Director Suite 9.0.554 - những tính năng quản lí đĩa phổ biến trong một công cụ riêng lẻ
* Paragon Partition Manager 7.0.1274 - Công cụ phân vùng đa năng
* Partition Commander 9.01 - Phân vùng ổ cứng an toàn, với tính năng undo
* Ranish Partition Manager 2.44 - Trình quản lí khởi động và phân vùng
* The Partition Resizer 1.3.4 - Di chuyển và định cỡ phân vùng
* Smart Fdisk 2.05 - Trình quản lí phân vùng ổ cứng đơn giản
* SPecial Fdisk 2000.03t - Công cụ phân vùng SPFDISK
* eXtended Fdisk 0.9.3 - XFDISK cho phép dễ dàng tạo và chỉnh sửa phân vùng
* GDisk 1.1.1 - Thay thế hoàn hảo cho tiện ích DOS FDISK và hơn thế
* Super Fdisk 1.0 - Tạo, xóa, định dạng phân vùng mà không hủy dữ liệu
* Partition Table Editor 8.0

Các công cụ sao lưu đĩa:
* ImageCenter 5.6 (Drive Image 2002) - Phần mềm tốt nhất để sao lưu ổ cứng
* Norton Ghost 11.5 - Tạo ảnh đĩa phổ biến (Hỗ trợ USB)
* Acronis True Image 8.1.945 - Tạo ảnh đĩa chính xác giúp sao lưu hệ thống và sao chép ổ đĩa
* Partition Saving 3.60 - Công cụ sao lưu/phục hồi phân vùng
* COPYR.DMA Build013 - Công cụ giúp tạo bản sao của ổ cứng bị hỏng sector

Các công cụ diệt virus:
* McAfee Antivirus 4.4.50 (2909) - chương trình quét virus (hỗ trợ ntfs và trình đơn dễ dùng)

Các công cụ phục hồi :
* Active Partition Recovery 3.0 - Phục hồi phân vùng bị xóa
* Active Uneraser 3.0 - Khôi phục các file và thư mục trên hệ thống FAT và NTFS
* Ontrack Easy Recovery Pro 6.10 - Phục hồi dữ liệu bị xóa/ virus tấn công
* Winternals Disk Commander 1.1 - Còn hơn cả một tiện ích phục hồi file bình thường
* TestDisk 6.10 - Công cụ kiểm tra và phục hồi phân vùng
* Lost & Found 1.06 - Phần mềm khôi phục dữ liệu cũ
* DiyDataRecovery Diskp@tch 2.1.100 - Phần mềm khôi phục dữ liệu xuất sắc
* Prosoft Media Tools 5.0 1.1.2.64 - Một phần mềm xuất sắc khác với nhiều tùy chọn
* Prosoft Media Tools 5.0 1.1.2.64 - Một trình phục hồi tập tin tuyệt vời với nhiều lựa chọn
* PhotoRec 6.10 - Công cụ phục hồi file và ảnh

Các công cụ kiểm tra:
* System Speed Test 4.78 - Kiểm tra CPU, ổ cứng ...
* PC-Check 6.5 - Công cụ kiểm tra phần cứng dễ dùng
* Ontrack Data Advisor 5.0 - Công cụ chẩn đoán mạnh mẽ giúp đánh giá điều kiện hoạt động của máy tính
* The Troubleshooter 7.02 - mọi thể loại công cụ kiểm tra phần cứng
* PC Doctor 2004 - công cụ đo hiệu năng và xem thông tin
* CPU/Video/Disk Performance Test 5.7 - công cụ kiểm tra CPU, video, ổ đĩa ...
* Test Hard Disk Drive 1.0 - công cụ kiểm tra ổ cứng

Các công cụ kiểm tra bộ nhớ
* DocMemory 3.1b - Tiện ích kiểm tra RAM
* GoldMemory 5.07 - Tiện ích kiểm tra RAM
* Memtest86+ 2.01 - Kiểm tra bộ nhớ máy tính

Các công cụ ổ cứng:
* Hard Disk Diagnostic Utilities
+ Seagate Seatools Desktop Edition 3.02
+ Western Digital Data Lifeguard Tools
+ Western Digital Diagnostics (DLGDIAG) 5.04f
+ Maxtor PowerMax 4.23
+ Maxtor amset utility 4.0
+ Maxtor(or any Hdd) Low Level Formatter 1.1
+ Fujitsu HDD Diagnostic Tool 7.00
+ Fujitsu IDE Low Level Format 1.0
+ Samsung HDD Utility(HUTIL) 2.02
+ Samsung Disk Diagnose (SHDIAG) 1.28
+ IBM/Hitachi Drive Fitness Test 4.14
+ IBM/Hitachi Feature Tool 2.11
+ Gateway GwScan 5.12
+ ExcelStor's ESTest 4.20
+ MHDD 4.6
+ WDClear 1.30
+ Toshiba Hard Disk Diagnostic 2.00b
+ SeaTools for Dos 1.10
* HDD Regenerator 1.51 - Khôi phục ổ cứng hỏng
* HDAT2 4.53 - Tính năng chính là kiểm tra và sửa các sector bị hỏng cho thiết bị
* Ontrack Disk Manager 9.57 - công cụ kiểm tra/ định dạng/ duy trì ổ đĩa
* Norton Disk Doctor 2002 - công cụ sửa ổ đĩa hỏng, hoặc chẩn đoán ổ đĩa
* Norton Disk Editor 2002 - công cụ chỉnh sửa ổ đĩa, phục hồi dữ liệu thủ công mạnh mẽ
* Hard Disk Sentinel 0.02 - Theo dõi tình tạng, cấu hình và nhiệt độ đĩa cứng
* Active Kill Disk 4.1 - Xóa đè và hủy mọi dữ liệu trên ổ vật lí một cách an toàn
* SmartUDM 2.00 - Hard Disk Drive S.M.A.R.T. Viewer.
* Victoria 3.33e và 3.52rus - phần mềm miễn phí giúp chẩn đoán sơ qua ổ cứng
* HDD Erase 4.0 - Secure erase using a special feature built into most newer hard drives

Các công cụ thông tin hệ thống:
* Aida16 2.14 - công cụ thông tin hệ thống, trích ra các chi tiết về mọi thành phần của máy tính
* PCI and AGP info Tool (2909) - Công cụ thông tin PCI
* System Analyser 5.3u - Xem nhiều thông tin phần cứng
* Navratil Software System Information 0.60.32 - Công cụ thông tin hệ thống chuyên nghiệp
* Astra 5.40 - Công cụ thông tin hệ thống và báo cáo nâng cao
* HWiNFO 5.2.2 - Tiện ích thông tin hệ thống mạnh mẽ
* PC-Config 9.33 - Phát hiện phần cứng máy tính
* SysChk 2.46 - Chính xác tìm ra những gì ẩn dưới lớp vỏ máy tính
* CPU Identification utility 1.12 - Các thông tin CPU chi tiết
* CTIA CPU Information 2.7 - Một công cụ thông tin CPU khác

Các công cụ MBR (Master Boot Record) :
* MBR Work 1.07b - Tiện ích với một số tính năng MBR thường thấy và hiếm gặp
* MBR Tool 2.2.100 - Sao lưu, kiểm tra, phục hồi, chỉnh sửa, xóa bỏ, hiển thị, ghi lại ...
* DiskMan4 - Công cụ tất cả trong một cho cmos, bios, bootrecord và hơn thế
* BootFix Utility - Chạy tiện ích này nếu bạn bị lỗi 'Invalid system disk'
* MBR SAVE / RESTORE 2.1 - Công cụ BootSave và BootRest giúp lưu/ phục hồi MBR
* Boot Partition 2.60 - Thêm phân vùng vào Windows NT/2000/XP Multi-boot loader
* Partition Table Doctor 3.5 - Công cụ sửa/ tinh chỉnh mbr, bootsector, bảng phân vùng
* Smart Boot Manager 3.7.1 - Trình quản lí multi boot
* Bootmagic 8.0 - Công cụ dành cho các hệ điều hành multi boot
* MBRWizard 2.0b - Trực tiếp cập nhật và chỉnh sửa MBR (Master Boot Record)

Download