I’ve been looking into the word “pest”, and the dictionary showed me 害虫, but 虫 means insects, so I wonder whether the word 害虫 only means harmful insects or it also can be used to refer to other pests like snakes or rats?
昆虫 means insects. 虫 does not mean insects.
虫 means worms, and the meaning is roughly extended to creepy-crawlies, and is sometimes even extended to small animals, including insects, snakes, crabs, shrimps, tadpoles, frogs, clams, etc.
In ancient China, all the animals were classified into four categories, namely 虫鱼鸟兽, where small animals except fishes and birds were in the 虫 category.