This is an interesting question. There many groups that directly or indirectly have a influence on funding for science. First, I would say that the government has a big part. Many governments directly fund science projects. For example, NASA was funded through the government here in the US.
Second, charitable endowments also give grants for research. Third, universities also play a role in science. Places such as MIT and California Institute of Technology have lots of money and some of that money goes to finance research, not to mention they train the next generation of great scientists.
Fourth, there is the private sector. Companies such as Merck and other pharmacy companies play a role on science funding. Fifth, the military also have a role in science funding.