difference between ip.src!=ADDR and !ip.src==ADDR - wireshark

Say that my IP address is 192.168.1.12 and I want to see traffics that don't contain my IP address using a display filter.
The result of filter "!ip.src==192.168.1.12 and !ip.dst==192.168.1.12" differs from that of filter "ip.src!=192.168.1.12 and ip.dst!=192.168.1.12". This is so weird, can anyone explain it to me?
BTW, I've checked the wireshark's doc 6.4.7. A Common Mistake with !=, and I'm sure that I'm not making the same mistakes here.

This is an analogon from the analog world: There are differences between
"show me apples that are not red"
and
"don't show me red apples".
What would you do with green apples?
The Wiresahrk display filters work similar. If you specify !ip.addr==192.168.1.12 you will suppress all IP packets sent from the specified IP address. But you don't suppress other packets like e.g. ARP packets.
But if you specify ip.addr!=192.168.1.12 you get only IP packets sent from any host except the specified IP address. You will see less packets.
Since you want to check for source or destination address I use ip.addr. That's an abbreviation for that purpose.

If you want to filter traffic that don't contain IP address : "192.168.1.12" then you have below two options.
Option: 1
Instead of specific source and specific destination filters, you can use below filter:
!(ip.addr == 192.168.1.12)
Option: 2
If you want to use both source and destination filter then logical operation will be "OR". you can use below filter:
!(ip.src == 192.168.1.12 or ip.dst == 192.168.1.12)

Related

How to use filters in the wireshark?

I try to capture http traffic with Wireshark and cant implement filters.
For example, I need filtered traffic by URL. I found solution in the tutorial https://www.wireshark.org/docs/man-pages/wireshark-filter.html
So I try to follows but have the error syntax error in the filter expression or invalid capture filter:
How to correctly use filters in the Wireshark?
Step – 1: Select correct interface
You need to choose the interface you're sniffing data from. If you are using wireless router to connect internet, then select the Wi-fi: en0 option.
If you are confused with many options, please remove unwanted connected devices to reduce the options, also open any YouTube video so that you can see the traffic fluctuation on your internet link interface. Note that straight line next to interface means no active traffic on that interface.
(Refer below video for detail information:
https://www.youtube.com/watch?v=1wB3ku4TSLY)
Step-2 : Design correct filter
To apply correct filter, you should know the public IP address or port (or both). In your case, open cmd prompt (windows user) and Nslookup your URL to find the ip address
(Refer video for detail information : https://www.youtube.com/watch?v=5DzG2hKAZ9U)
Hence your filter is “ip.addr == 104.26.11.240”
Step-3 : Apply filter
Instead of “http contains “Google”” please Enter “ip.addr == 104.26.11.240” without double quotes.
And hit the enter key, your red filter Colour become green & you can see at the bottom
packets : (number1) . Displayed : (number2)
number1- total number of packets captured on interface
number2 - relevant number of packets on interface of www.wireshark.org
Step-4 : save packets
Save only relevant traffic (5 packets) and exclude the unwanted traffic (397 packets).
Click on file
Click on exports specified packets
Select filename & path
Select format pcapng
First you need to choose the interface you're sniffing data from. If you wish to sniff the the wireless data then select the Wi-fi: en0 option, then when the interface is sniffing and parsing the data you can then use the filters as you wish.
That area is for a capture filter, not a display filter. If you remove your text, you should see that it indicates, "Enter a capture filter ...". The area for entering a display filter is at the top of the screen where it indicates, "Apply a display filter ... <Ctrl-/>".
As the name suggests, capture filters are applied during capturing and use a different syntax than Wireshark's display filters, which are applied after packets have already been captured when working with a capture file. For more information on capture filter syntax, refer to the pcap-filter man page.
For more information on Wireshark display filters, refer to section 6.4. Building Display Filter Expressions in the Wireshark User's Guide.

Structuring Wireshark dissector to make filtering easier

I am writing my first Wireshark dissector. I am writing it in Lua, using this as an example. My communication protocol embeds a command ID in the response header, followed by well-defined payloads that differ based on the command ID. So far, I've been structuring the ProtoFields such that the Abbreviated name of the field (the string used in filters) follows a naming convention like this
proto_name.command_name.field_name
Some commands have similar fields, like in the following example
myproto.cmd_update.updateId
myproto.cmd_update_ack.updateId
where, per the protocol, an update command must be acknowledged with a update_ack command with the same updateId payload. Ideally, i would like to create a wireshark filter such that I can see all packets pertaining to the updateId field. I tried creating a filter like
myproto.*.updateId == 0x1234
but that appears to be invalid wireshark filter syntax. I don't want to make the filter explicit like
myproto.cmd_update.updateId == 0x1234 or myproto.cmd_update_ack.updateId == 0x1234
because in my actual protocol there are many more commands with similar/related fields. Is there a filter syntax I can use? Or perhaps, should I structure my dissector's ProtoField abbreviations differently?
There doesn't appear to be a wildcard syntax for the filter line, so I wound up solving this in the dissector itself. In addition to the myproto.*.updateId fields, I also added another field called myproto.updateId (note the lack of the wildcard in the middle). Its value is set to the same thing as the full blown field name, which means that I now have just one field name to search against. I also set this field as hidden = true to hide it from view.
It's a bit of a hack, but gives me what I want.
You could try using a Wireshark display filter macro.

How to get asnum and org values for the IP address with lua-geoip?

I am using the lua-geoip library.
How do I use "geoip asnum" and "geoip org" to get the asnum and org value from ipaddress using lua script?
If I understand correctly your question, you're looking to get an Autonomous System Number and ISP Organization for an IP address.
These values are stored in two databases: GeoIPASNum.dat and GeoIPOrg.dat. (Note that ASN number already contains an organization name, which may be sufficient for your purposes, for example: "AS15169 Google Inc.".)
At this moment the lua-geoip (v0.1.2) does not support either of these files.
You may add this support by cloning the country db, replacing country with asnum in the text.
https://github.com/agladysh/lua-geoip/blob/master/src/country.c
Then change query functions to use GeoIP_org_by_name instead of GeoIP_id_by_name — and push the result as a string, not country_info.
The process should be similar for the org DB should you need it.
See usage here:
https://github.com/maxmind/geoip-api-c/blob/master/test/test-geoip-asnum.c
https://github.com/maxmind/geoip-api-c/blob/master/test/test-geoip-org.c
(Full disclosure: I'm the maintainer of lua-geoip)

How to filter wireshark to display only packets between a server and a client?

I am new to wireshark and trying to write simple filters. What i am trying to do is the following: I want to write a filter so that only the packets between my computer and a specified server appear in the packets pane. Here is what i tried:
ip.src==159.20.94.8 and ip.dst==10.1.1.7
First one is the ip address of my computer, and second one is the ip address of the server. But there is also the opposite of this, in which source is the server and destination is my computer.
ip.src==10.1.1.7 and ip.dst==159.20.94.8
So my question is, how can i combine these two filters? Or is there a simpler way for this filtering?
Thanks
Use ip.addr==159.20.94.8 and ip.addr==10.1.1.7
I know that doesn't seem to make sense, but ip.addr matches either source or destination.
Use ip.addr==10.0.0.1 or ip.addr==10.0.0.2.
Using the OR operator will give you results in both ways(Source and Destination).

How to get a page from a userspace process for a given task in Linux?

What exactly does the virt_to_page function return, does it return the page given an address in the kernel space or does it return a page given an address in user space? As far as I can tell it seems that it takes a kernel address and returns the page for that. If so what can I use to get a page from a user space process given the task or mm_struct and then virtual address?
virt_to_page() does indeed work only for direct-mapped kernel addresses. To find a page for a userspace mapping, you need to use get_user_pages() (and do a put_page when you're done to release the reference on the page).

Resources