Perl RawIP CWR Flag - perl

I'm using Net::RawIP to send packets with specific TCP flags. Is there a way to set the CWR flag?
TCP protokey "res2" sets the ECE flag, but "res1" seems to set the NS flag:
$n = Net::RawIP->new({
ip => {
saddr => 'my.target.lan',
daddr => 'my.target.lan',
},
tcp => {
source => 123,
dest => 123,
res1 => 1,
res2 => 1,
fin => 1,
syn => 1
}
});
Here's a Wireshark capture of the packet's flags:

res2 is two bits wide.
res2 => 1 # ECE
res2 => 2 # CWR
res2 => 3 # ECE & CWR
(It might be the opposite on big-endian machines, but I doubt it.)
(res1 is the 4 bits labeled as "Reserved" and "Nonce" in the Wireshark capture.)

Related

Error when using the SoftLayer Ruby API to specify a flavor

I have a working ruby script that we have been using for a quite a while to order VSIs from SoftLayer. The script specifies a certain price item for CPU, one for memory, and another for disk. I am trying to modify the script to work with flavors but I have been unable to figure out what I am doing wrong. Basically I have removed the CPU, memory, and disk price items from the product order and added in a flavorKeyName in the supplementalCreateObjectOptions like this:
#!/usr/bin/ruby
require 'softlayer_api'
client = SoftLayer::Client.new(username: 'XXXXX', api_key: 'XXXXX')
productOrder = {
'virtualGuests' => [{
'hostname' => 'test',
'domain' => 'mycompany.com',
'primaryNetworkComponent' => { 'networkVlan' => { 'id' => XXXXXX } },
'primaryBackendNetworkComponent' => { 'networkVlan' => { 'id' => XXXXXX },
'supplementalCreateObjectOptions' => { 'flavorKeyName' => 'B1_1X2X100' } }
}],
'location' => XXXXXX,
'packageId' => 46,
'imageTemplateId' => XXXXX,
'useHourlyPricing' => true,
'prices' => [
{'id' => 34183 }, # 0 GB Bandwidth
{'id' => 24713 }, # 1 Gbps Public & Private Network Uplinks
{'id' => 34807 }, # 1 IP Address
{'id' => 33483 }, # Unlimited SSL VPN Users & 1 PPTP VPN User per account
{'id' => 34241 }, # Host Ping and TCP Service Monitoring
{'id' => 32500 }, # Email and Ticket
{'id' => 35310 }, # NESSUS_VULNERABILITY_ASSESSMENT_REPORTING
{'id' => 23070 }, # REBOOT_REMOTE_CONSOLE
{'id' => 32627 } # AUTOMATED_NOTIFICATION
]
}
order = client['Product_Order'].verifyOrder(productOrder)
but this fails with:
/usr/lib64/ruby/2.1.0/xmlrpc/client.rb:271:in `call': Internal Error (XMLRPC::FaultException)
from /usr/lib64/ruby/gems/2.1.0/gems/softlayer_api-3.2.2/lib/softlayer/Service.rb:269:in `call_softlayer_api_with_params'
from /usr/lib64/ruby/gems/2.1.0/gems/softlayer_api-3.2.2/lib/softlayer/Service.rb:198:in `method_missing'
from /tmp/yy2:34:in `<main>'
The error is not too helpful on what I might be specifying incorrectly or might be missing.
Does any one have a suggestions on what I might be doing wrong?
When using Softlayer_Product_Order::verifyOrder or Softlayer_Product_Order::placeOrder you need to use the package 835, and set the presetId parameter to specify what flavor configuration you want to order.
The supplementalCreateObjectOptions parameter is specified when using the SoftLayer_Virtual_Guest::createObject method.
Following are two ways to order virtual guest devices with a flavor configuration.
PlaceOrder
To get the list of available preset ids for package 835 you need to use the method SoftLayer_Product_Package::getActivePresets.
https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/835/getActivePresets
Check the keyName values to know which are Balanced, Memory, etc., they should start with:
B1 is for "Balanced"
BL1 is for "Balanced Local Storage"
BL2 is for "Balanced Local Storage - SSD"
C1 is for "Compute"
M1 is for "Memory"
These characters are followed by a short description of VSI configuration as following:
C1_2X2X100 for Compute VSI with "2 x 2.0 GHz Cores, 2 GB RAM, 100 GB Disk"
B1_8X16X25 for Balanced VSI with "8 x 2.0 GHz Cores, 16 GB RAM, 25 GB Disk"
If I'm not wrong the presetId 333 is for B1_1X2X100 which is the flavor configuration you want.
require 'rubygems'
require 'softlayer_api'
require 'json'
# Your SoftLayer API username and API Key.
USERNAME = 'set-me'
API_KEY = 'set-me'
# Location where server will be provisioned.
location = 'AMSTERDAM03'
# The id of the SoftLayer_Product_Package, use the 835 for VSI Families.
package_id = 835
# Following is the preset id used to complete this example.
preset_id = 333 # B1_1X2X100 (1 x 2.0 GHz Cores, 2 GB RAM, and primary disk of 25 GB)
# The number of servers you wish to order in this configuration.
quantity = 1
# Build a skeleton SoftLayer_Virtual_Guest object. If you set quantity greater than 1
# then you need to define one hostname/domain per server you wish to order.
virtual_guest = [
{
'hostname' => 'test-vsi',
'domain' => 'mycompany.com',
'primaryNetworkComponent' => { 'networkVlan' => { 'id' => 11111 } },
'primaryBackendNetworkComponent' => { 'networkVlan' => { 'id' => 22222 }}
}
]
# Specify the item prices. Note that you don't need to specify the item price for
# cpus, ram, and primary disk, and take into account that “Balanced Local Storage”
# and “Balanced Local Storage - SSD” requires a second disk, the system will select one
# if you don’t specify it.
prices = [
{'id' => 34183 }, # 0 GB Bandwidth
{'id' => 24713 }, # 1 Gbps Public & Private Network Uplinks
{'id' => 34807 }, # 1 IP Address
{'id' => 33483 }, # Unlimited SSL VPN Users & 1 PPTP VPN User per account
{'id' => 34241 }, # Host Ping and TCP Service Monitoring
{'id' => 32500 }, # Email and Ticket
{'id' => 35310 }, # NESSUS_VULNERABILITY_ASSESSMENT_REPORTING
{'id' => 23070 }, # REBOOT_REMOTE_CONSOLE
{'id' => 32627 } # AUTOMATED_NOTIFICATION
]
# Build a skeleton SoftLayer_Container_Product_Order object containing the order
# you wish to place.
order_template = {
'quantity' => quantity,
'location' => location,
'packageId' => package_id,
'presetId' => preset_id,
'imageTemplateId' => 1111111,
'useHourlyPricing' => true,
'prices' => prices,
'virtual_guest' => virtual_guest
}
# Declare the API client to use the SoftLayer_Product_Order API service
client = SoftLayer::Client.new(username: USERNAME, api_key: API_KEY)
product_order_service = client.service_named('SoftLayer_Product_Order')
begin
# verifyOrder() will check your order for errors. Replace this with placeOrder()
# when you're ready to order.
receipt = product_order_service.verifyOrder(order_template)
puts JSON.pretty_generate(receipt)
rescue StandardError => exception
puts "There was an error in your order: #{exception}"
end
CreateObject
Take account that createObject method is a simplified way to order virtual guest devices so you may not be able to set items like IPV6, secondary IP address, etc. See SoftLayer_Virtual_Guest::createObject to know which properties you can set.
The following example is to order a vsi family with flavor configuration B1_1X2X100, on this case it is necessary to set the parameter supplementalCreateObjectOptions
require 'rubygems'
require 'softlayer_api'
require 'json'
# Your SoftLayer API username and API Key.
USERNAME = 'set-me'
API_KEY = 'set-me'
# Build the skeleton of SoftLayer_Virtual_Guest object.
virtual_guest_template = {
'hostname' => 'test-vsi',
'domain' => 'mycompany.com',
'primaryNetworkComponent' => { 'networkVlan' => { 'id' => 11111 } },
'primaryBackendNetworkComponent' => { 'networkVlan' => { 'id' => 22222 }},
'datacenter' => { 'name' => 'dal05' },
'supplementalCreateObjectOptions' => {
'flavorKeyName' => 'B1_1X2X100'
},
'hourlyBillingFlag' => true,
# Following is to specify the imageTemplate you want to use. But on this case you need
# to set the globalIdentifier of imageTemplate.
'blockDeviceTemplateGroup' => {
'globalIdentifier' => '6x06c3x8-4158-4b69-ba5x-433c18x3xac3'
},
'networkComponents' => [
{ 'maxSpeed' => 1000} # 1 Gbps Public & Private Network Uplinks
]
}
# Declare the API client to use the SoftLayer_Virtual_Guest API service
client = SoftLayer::Client.new(username: USERNAME, api_key: API_KEY)
virtual_guest_service = client['SoftLayer_Virtual_Guest']
begin
# Call to createObject() when you're ready to order.
# Call to generateOrderTemplate() if you want to create an order container that can be
# used with the methods verifyOrder and placeOrder.
virtual_guest = virtual_guest_service.createObject(virtual_guest_template)
puts JSON.pretty_generate(virtual_guest)
rescue StandardError => exception
puts "There was an error in your order: #{exception}"
end

Perl RawIP maximum data size

I'm trying to send some data over TCP using Net::RawIP in Perl. Unfortunately i get the error
sendto() at /usr/lib/x86_64-linus-gnu/perl5/5.24/Net/RawIP.pm line 630
if the TCP data field is bigger than about 1470 characters:
my $n = Net::RawIP->new({
ip => {
saddr => '[src]',
daddr => '[dst]',
},
tcp => {
source => 7777,
dest => 7777,
data => "x" x 150
}
});
$n->send;
works, but
my $n = Net::RawIP->new({
ip => {
saddr => '[src]',
daddr => '[dst]',
},
tcp => {
source => 7777,
dest => 7777,
data => "x" x 1500 # size changed here
}
});
$n->send;
crashes. Any ideas why this happens?
You're building a packet that's too large, so sendto is returning error EMSGSIZE.
EMSGSIZE
The socket type requires that message be sent atomically, and the size of the message to be sent made this impossible.
It's no mystery it starts failing around 1500; that's the maximum an Ethernet frame can carry.
You need to use multiple packets or multiple packet fragments.

how to set tcp options (MSS value) in Net::RawIP

Can i set Maximum segment size to some value when using Net::RawIP?
I am trying the below code but don't know how can i set MSS value in TCP options to custom value.
#!/usr/bin/perl
use Net::RawIP;
$packet = new Net::RawIP;
$packet->set({
ip => {
saddr => '192.168.122.128',
daddr => '192.168.122.1'
},
tcp => { source => 2323,
dest => 8080,
syn => 1,
seq => 100,
ack_seq => 0,
data => 'hello world'
}
});
$packet->optset(tcp => { type => [ (2) ], data => [ (10) ] });
$packet->send(0, 1);
According to the documentation:
optset(OPTPROTO => { type => [...],data => [...] },...)
[...] The value of the data also is an array reference. This array must be filled with strings which must contain all bytes from a option except bytes with type and length of an option.
(emphasis added)
You're passing a reference to an array of integers; you need to pass a reference to an array of strings. Try something like this:
$packet->optset( tcp => { type => [ 2 ], data => [ "\x00\x0A" ] } );
The length of the maximum segment size field is 4, which includes one byte for the kind field, one byte for the length field, and two bytes for the data itself, so you need to pass a two-byte string as above.

How do I specify packet data in Net::RawIP?

According to the cpan documentation I can create a raw packet with the following code:
use Net::RawIP;
$n = Net::RawIP->new({
ip => {
saddr => 'my.target.lan',
daddr => 'my.target.lan',
},
});
tcp => {
source => 139,
dest => 139,
psh => 1,
syn => 1,
},
});
$n->send;
But where do I declare the data the packet contains?
Can I send the packet with another module?
Since you are sending a tcp packet you need as the documentations says to specify:
$n = Net::RawIP->new({
ip => {
saddr => 'my.target.lan',
daddr => 'my.target.lan',
},
tcp => {
source => 139,
dest => 139,
psh => 1,
syn => 1,
data => $your_data
},
});

How to manipulate and send packets caught with Net::PCAP on windows

I need to change the tcp/ip headers of packets caught with Net::PCAP. I know this is possible with Net::RawIP, but this doesn't work under windows?
Is there a module for this that works with windows? Is there at least to do this in windows with another programming language that I can call in perl, such as C?
To demonstrate what I want to do, here is the code using Net::RawIP, which does not work under windows because I can't install the module:
$n = Net::RawIP->new({
ip => {
saddr => 'my.target.lan',
daddr => 'my.target.lan',
},
tcp => {
source => 139,
dest => 139,
psh => 1,
syn => 1,
data => $your_data
},
});
$n->send();
Try pcap_sendpacket using this per module https://metacpan.org/pod/Net::Pcap