Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

support partition in network attack #65

Merged
merged 23 commits into from
Oct 9, 2021

Conversation

WangXiangUSTC
Copy link
Collaborator

@WangXiangUSTC WangXiangUSTC commented May 7, 2021

Usage

./bin/chaosd attack network partition --help
partition

Usage:
  chaosd attack network partition [flags]

Flags:
      --accept-tcp-flags string   only the packet which match the tcp flag can be accepted, others will be dropped. only set when the protocol is tcp.
  -d, --device string             the network interface to impact
      --direction string          specifies the partition direction, values can be from, to
  -h, --help                      help for partition
  -H, --hostname string           only impact traffic to these hostnames
  -i, --ip string                 only impact egress traffic to these IP addresses
  -p, --protocol string           only impact traffic using this IP protocol, supported: tcp, udp, icmp, all

Global Flags:
      --log-level string   the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

Examples

sudo ./bin/chaosd attack network partition --ip 172.16.112.136 -d ens33

If you want to block only part of the packet, you can set the accept-tcp-flags(only for tcp protocol), just like:

sudo ./bin/chaosd attack network partition --ip 172.16.112.136 -d ens33 -p tcp  --accept-tcp-flags "SYN,ACK SYN,ACK" --direction to

And then you can start a simple HTTP server by python:

python3 -m http.server 9288

Send HTTP request from 172.16.112.136:

 wget 172.16.112.130:9288
--2021-05-07 03:49:56--  http://172.16.112.130:9288/
Connecting to 172.16.112.130:9288... connected.
HTTP request sent, awaiting response...

You will see it is waiting the response, and the HTTP server receive the request:

172.16.112.136 - - [07/May/2021 03:49:56] "GET / HTTP/1.1" 200 -

But the response is blocked.

Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
@WangXiangUSTC WangXiangUSTC added enhancement New feature or request and removed WIP labels May 26, 2021
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
@Andrewmatilde
Copy link
Member

Example sudo ./bin/chaosd attack network partition --ip 172.16.112.136 -d ens33 -p tcp --accept-tcp-flags "SYN,ACK SYN,ACK --direction to"not work.
Return error Error: direction not supported.
I think more comment about direction is necessary for the direction option.And I think the main problem is the subject of direction is missing.

@Andrewmatilde
Copy link
Member

Andrewmatilde commented May 27, 2021

I also find the config of iptables was not cleared well.
2021-05-27 14-51-07 的屏幕截图

@WangXiangUSTC
Copy link
Collaborator Author

sudo ./bin/chaosd attack network partition --ip 172.16.112.136 -d ens33 -p tcp --accept-tcp-flags "SYN,ACK SYN,ACK --direction to"

I take a mistake in the description, the command should be sudo ./bin/chaosd attack network partition --ip 172.16.112.136 -d ens33 -p tcp --accept-tcp-flags "SYN,ACK SYN,ACK" --direction to

@@ -66,6 +72,8 @@ func (n *NetworkCommand) Validate() error {
return n.validNetworkCommon()
case NetworkDNSAction:
return n.validNetworkDNS()
case NetworkPartitionAction:
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really unnecessary to valid action?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, require a validate, done in dcb1285

cmd.Flags().StringVarP(&options.IPProtocol, "protocol", "p", "",
"only impact traffic using this IP protocol, supported: tcp, udp, icmp, all")
cmd.Flags().StringVarP(&options.AcceptTCPFlags, "accept-tcp-flags", "", "", "only the packet which match the tcp flag can be accepted, others will be dropped. only set when the protocol is tcp.")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that user may drop ssh package with partition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, SSH uses TCP protocol in the transport layer.

Signed-off-by: xiang <xiang13225080@163.com>
@WangXiangUSTC
Copy link
Collaborator Author

add some description of direction in dcb1285 @Andrewmatilde

Signed-off-by: xiang <xiang13225080@163.com>
Signed-off-by: xiang <xiang13225080@163.com>
@WangXiangUSTC
Copy link
Collaborator Author

@Andrewmatilde PTAL again

Signed-off-by: xiang <xiang13225080@163.com>
@WangXiangUSTC
Copy link
Collaborator Author

just ignore the lift's warning now, because it's not the real version we used, there is a replace in the go.mod 😢

@@ -378,6 +412,45 @@ func (n *NetworkCommand) NeedApplyTC() bool {
}
}

func (n *NetworkCommand) ToChain(ipset string) ([]*pb.Chain, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ToChain is not a good name to explain what the func do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe NetworkPartitionChains?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,I update to PartitionChains without Network, because the object's type is NetworkCommand

@Andrewmatilde
Copy link
Member

I think we need a verbose option and log all the iptables command inTrace log level.

@WangXiangUSTC
Copy link
Collaborator Author

I think we need a verbose option and log all the iptables command inTrace log level.

Good idea, I will do it in another pr

Signed-off-by: xiang <xiang13225080@163.com>
Copy link
Member

@Andrewmatilde Andrewmatilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@WangXiangUSTC
Copy link
Collaborator Author

@fewdan PTAL

Copy link
Member

@fewdan fewdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fewdan fewdan merged commit 693b6f7 into chaos-mesh:main Oct 9, 2021
@WangXiangUSTC WangXiangUSTC deleted the xiang/partition branch October 11, 2021 03:12
@WangXiangUSTC WangXiangUSTC mentioned this pull request Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants